[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Compiler directive for definition of popen?



Which compiler directive to use to get the definition of popen included
in the file. It does not seem to be included by default, and
-D__USE_POSIX2 etc does not work either. Have been googling around but
not found anything usable so far.

popen is NOT defined: gcc -ansi -Wall -pedantic test.c
test.c: In function 'open_gnuplot':
test.c:25: warning: implicit declaration of function 'popen'

popen is defined: gcc -Wall -pedantic test.c

In the test case below no runtime error occurs but in the real
application is does!

Different compilers have been tried: 2.95,3.3,3.4,4.0,4.1

test.c:
#include <stdio.h>
                                                                                 
#define SIX 1 + 5
#define NINE 8 + 1
                                                                                 
int main(void)
{
  FILE  *open_gnuplot();
  static FILE *GNU = {0}; /* Pointer to gnuplot commands */
  GNU = open_gnuplot();
  fprintf(GNU,"plot sin(x)/x\n");
  printf( "The meaning of life: %d\n", SIX * NINE );
  getchar();
  return 0;
}

FILE *open_gnuplot()
{
  FILE *fileptr;
  if(!(fileptr=(FILE *)popen("gnuplot -persist","w"))) {
    printf("Unable to open pipe to gnuplot for writing\n");
    return NULL;
  }
    return fileptr;
}

Please cc: me since I'm not subscribed to this list.

Thanks,
-- 
Svante Signell <svante.signell@telia.com>



Reply to: