Python embedding in C ++ libraries

I am working on embedding Python in some C ++ code, but I am forcing it to compile.

For the header file, I have

#include <Python.h> 

I would try

 $g++ EmbeddedPython.cpp 

but in the end

 EmbeddedPython.cpp:1:20: error: Python.h: No such file or directory EmbeddedPython.cpp: In function 'int main(int, char**)': EmbeddedPython.cpp:6: error: 'Py_Initialize' was not declared in this scope .... 

Then i tried

 g++ EmbeddedPython.cpp -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 

and it got rid of the first two errors, but I still ended up with

  Undefined symbols: "_Py_Initialize", referenced from: _main in ccxJAUAB.o 

I'm a little new to this, but I think I'm learning fast. I think I need to "link" the library, right? But which one and how? Do I need dynamic or static?

I am working on a MacBook Pro.

+4
source share
1 answer

You need to set the link to libpython. UNIX programmers do this with "-lpython" in the link command (that is, at the end of this g ++ command). On Mac, I think it will be "-framework Python".

+4
source

All Articles