I am trying to run gnuplot from a c++ program in a portable fashion. Ironically enough for WIN_32 I have no problem, but my compiler (visual studio 2015)can't identify the POSIX command popen() that I am trying to use for other OS. Is popen() nonexistent in C++11, is there an equivalent or must I change standards?
this compiles and runs in windows visual studio 2015 :
#include <stdio.h>
#include <stdlib.h>
int main()
{
_popen(" ", "w");
return 0;
}
this does not compile :
#include <stdio.h>
#include <stdlib.h>
int main()
{
popen(" ", "w");
return 0;
}
error
Error C3861 'popen': identifier not found
at the end of the day, I want a behavior like
#include <stdio.h>
#include <stdlib.h>
int main()
{
#ifdef WIN_32
_popen(" ", "w");
#else
popen(" ", "w");
#endif
return 0;
}
I expect this program to be recompiled in g++ when used on Linux and Mac, but I would like to use msvc14 to compile on windows
popen() is indeed not present in C++ (any version). It's defined by posix, and so available on most unix like operating systems.
There is no popen() function on windows, but there is the equivalent _popen() function that you can use
MSVC pre-defines the _WIN32 constant, which you could use for conditional compiling, .e.g
#ifdef _WIN32
_popen(" ", "w");
#else
popen(" ", "w");
#endif
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