Re: popen()

Jens.Toerring_at_physik.fu-berlin.de
Date: 02/28/04


Date: 28 Feb 2004 00:58:18 GMT

Pai-Yi Hsiao <hsiao@ccr.jussieu.fr> wrote:
> How to *correctly* compile a C code containing popen()?
> I know that popen() is not an ANSI function.
> I got some warnings while using gcc to compile the code:
> [I have included #include<stdio.h> in the header.]

> $gcc -ansi -Wall -pedantic test.c
> test.c: In function `main':
> test.c:9: warning: implicit declaration of function `popen'
> test.c:9: warning: assignment makes pointer from integer without a cast
> test.c:18: warning: implicit declaration of function `pclose'

The problem is that you tell the compiler to be real picky and barf
at all non-standard functions by using the -ansi and -pedantic flags.
But since popen() and pclose() aren't standard functions they won't
get declared in the headers in this case. So you either need to drop
that flags or you must have some additional defines. At least for the
system I am currently sitting at you need to #define either
__USE_POSIX2, __USE_SVID or __USE_BSD to get the declarations for
popen() and pclose(). Alternatively, you can declare them yourself.
as

extern FILE *popen( const char *command, const char *modes);
extern int pclose(FILE *stream);

                                     Regards, Jens

-- 
  \   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
   \__________________________  http://www.toerring.de


Relevant Pages