I need to use popen
in a project, but I get:
error: 'popen' was not declared in this scope
It looks like GCC defines __STRICT_ANSI__
under both -std=c++0x
and (contrary to what little information I was able to find) -std=gnu++0x
, which causes popen
(and _popen
) to be elided from stdio
. Oddly enough, undefining __STRICT_ANSI__
doesn't solve the issue, nor does forward-declaring the function. I'm obviously missing something. Is there a reasonable workaround?
I was using MinGW with 4.5.0, and upgraded to 4.5.2, but am still experiencing the same problem. I'd rather not have to muck about with msys to compile 4.6.0, but I will if I must.
I'm simply undefining it on the commandline right away, this is not terribly "clean" but it works fine from what I can tell.
-std=gnu++0x -U__STRICT_ANSI__
There is probably a good reason why one should not do that, but it gives me what I want (C++0x plus GNU extensions, plus legacy stuff still works). I've been doing this for a long time and never run into trouble. But don't blame me if it eats your cat.
I tested both MinGW gcc 4.6.1 and gcc 4.7.0: They both do define __STRICT_ANSI__
for -std=c++0x
, but do not define it for -std=gnu++0x
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With