0

I am using popen() in a C++ program. I see that they are C functions defined in stdio.h. I am trying to get my IDE (KDevelop 4) to recognize popen().

I looked into the actual source code stdio.c. In here, popen does not appear "wrapped" by any macros or anything - it appears like any other typical function of stdio.h

Why, then, is popen() not recognized by my IDE? #include <stdio.h> should be all that is needed, but it doesn't work...

I noticed in the MAN pages they talk about Feature Test Macros. In stdio.h, popen() is NOT wrapped by any macro (again, it appears like any other function). Additonally, when I do try including one of these macros, e.g. #define _POSIX_C_SOURCE 2, the problem is not resolved - popen() still goes unrecognized.

The program compiles (g++) and runs correctly though. I would just like to know what's going on here.

(Another thread on StackOverflow addresses this question but does not obtain a satisfactory answer: popen implicitly declared even though #include <stdio.h> is added)

Community
  • 1
  • 1
cmo
  • 3,762
  • 4
  • 36
  • 64
  • 2
    What do you mean by "not recognized"? – user973572 Dec 09 '11 at 14:25
  • "unrecognized" as in, unable to resolve namespace. The IDE does not recognize the function as declared, but at compile time all works fine. – cmo Dec 09 '11 at 14:28
  • 2
    Are you sure you're looking at the right stdio.h ? What happens if you just pre-process your source with/without the feature macro defined ? Also, does your stdio.h have the necessary `extern "C" { }` block for compiling with C++ ? – Paul R Dec 09 '11 at 14:28
  • 3
    You have to put the macros at the very top (or with `-D` on the command line), before any incude statements. Not just before stdio.h; before _any_ includes. – Random832 Dec 09 '11 at 14:42

0 Answers0