I’m trying to embed a Python script into a C++ application. Before I do such a thing though, I’m trying to run the example script.
Here’s my code:
#include <Python/Python.h>
int main(int argc, char *argv[]) {
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();
return 0;
}
Compiling with g++ gives me:
Undefined symbols:
"_Py_Initialize", referenced from:
_main in cc2Ogphq.o
"_PyRun_SimpleStringFlags", referenced from:
_main in cc2Ogphq.o
"_Py_Finalize", referenced from:
_main in cc2Ogphq.o
ld: symbol(s) not found
I’m running Mac OSX Snow Leopard and I’m running Python 2.7.2.
You need to link to the python libraries, e.g.
libpython.afor static linkage.