On linux, you can use python-config to get compiler flags (python-config -cflags) and linker flags (python-config -ldflags).
For instance:
#> python-config --cflags
-I/usr/include/python2.5 -I/usr/include/python2.5 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes
#> python-config --ldflags
-L/usr/lib/python2.5/config -lpthread -ldl -lutil -lm -lpython2.5
To compile your program, you can run g ++ useEmbed.cpp -o embed "cflags" "ldflags":
#> g++ useEmbed.cpp -o embed -I/usr/include/python2.5 -I/usr/include/python2.5 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -L/usr/lib/python2.5/config -lpthread -ldl -lutil -lm -lpython2.5
I had to modify useEmbed.cpp a bit:
#include "Python.h" #include <iostream> using namespace std; int main() { Py_Initialize(); FILE *file = fopen("embed.py","r+"); PyRun_SimpleFile(file,"embed.py"); Py_Finalize(); fclose(file); return 0; }
#include "Python.h" #include <iostream> using namespace std; int main() { Py_Initialize(); FILE *file = fopen("embed.py","r+"); PyRun_SimpleFile(file,"embed.py"); Py_Finalize(); fclose(file); return 0; }
source share