Embedded Python plus module loading
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Okay, I've put a minimal example together. http://dingoskidneys.com/~dholth/minimal-embedding-failure.zip It is the embedding example from boost, with an "import sha" statement added inside it. sha depends on some dynamically loaded code. When I try to run it, it says: ImportError: /usr/lib/python2.3/lib-dynload/sha.so: undefined symbol: Py_FindMethod My Jamfile: project-root ; # Include definitions needed for Python modules SEARCH on python.jam = $(BOOST_BUILD_PATH) ; import python ; # The boost-jam embedding example exe embedding ~ : # sources ~ embedding.cpp ~ : # requirements ~ <threading>multi ~ <find-library>boost_python ~ $(PYTHON_PROPERTIES) ~ <library-path>$(PYTHON_LIB_PATH) ~ <find-library>$(PYTHON_EMBEDDED_LIBRARY) ~ ; I'm not sure where I'm going wrong and I'd appreciate some advice. Embedded Python is more useful when you can load dso's. Thanks, Daniel Holth -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCPfdLVh4W2pVfoMsRAtsdAKC/d+5VZRWW5O1N1TgEKnVKnlZsFgCdEzTI D6y1iipDrSYmFAl36ykgtoE= =NcnH -----END PGP SIGNATURE-----
On Sun, 2005-03-20 at 17:20 -0500, Daniel Holth wrote:
My Jamfile:
project-root ;
# Include definitions needed for Python modules SEARCH on python.jam = $(BOOST_BUILD_PATH) ; import python ;
# The boost-jam embedding example exe embedding ~ : # sources ~ embedding.cpp ~ : # requirements ~ <threading>multi ~ <find-library>boost_python ~ $(PYTHON_PROPERTIES) ~ <library-path>$(PYTHON_LIB_PATH) ~ <find-library>$(PYTHON_EMBEDDED_LIBRARY) ~ ;
I'm not sure where I'm going wrong and I'd appreciate some advice. Embedded Python is more useful when you can load dso's.
I've figured it out, more or less. When I link to libpython2.3.so rather than the static Python library it works fine. Doesn't answer the question of why my other program suddenly stopped working re: importing, but it does fix it. # The boost-jam embedding example exe embedding : # sources embedding.cpp : # requirements <threading>multi # my system's Python library is threaded <find-library>python2.3 <find-library>boost_python ; which imports sha without incident. Except it doesn't set the include path, so the same jamfile won't both compile my code and link it. So now I just have to work out the arguments to get it to link with the shared library and set the include path properly... perplexing. Thanks for any advice, Daniel Holth
Daniel Holth <dholth@fastmail.fm> writes:
I've figured it out, more or less. When I link to libpython2.3.so rather than the static Python library it works fine. Doesn't answer the question of why my other program suddenly stopped working re: importing, but it does fix it.
# The boost-jam embedding example exe embedding : # sources embedding.cpp : # requirements <threading>multi # my system's Python library is threaded <find-library>python2.3 <find-library>boost_python ;
which imports sha without incident. Except it doesn't set the include path, so the same jamfile won't both compile my code and link it. So now I just have to work out the arguments to get it to link with the shared library and set the include path properly... perplexing.
Thanks for any advice,
The embedding example in libs/python/test/Jamfile looks like: run ../test/embedding.cpp <lib>../build/boost_python : # program args : # input files : # requirements $(PYTHON_PROPERTIES) <define>BOOST_PYTHON_STATIC_LIB <define>BOOST_PYTHON_STATIC_MODULE <library-path>$(PYTHON_LIB_PATH) <$(gcc-compilers)><debug-python><library-path>$(CYGWIN_PYTHON_DEBUG_DLL_PATH) <$(gcc-compilers)><*><library-path>$(CYGWIN_PYTHON_DLL_PATH) <find-library>$(PYTHON_EMBEDDED_LIBRARY) <define>BOOST_PYTHON_STATIC_LIB is not needed if you're using the shared version of Boost.Python. You can use <dll>@boost/libs/python/build/boost_python if you are using the cross-project dependencies to ensure that the right shared library is built and linked in. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com
Daniel Holth <dholth@fastmail.fm> writes:
Okay, I've put a minimal example together.
http://dingoskidneys.com/~dholth/minimal-embedding-failure.zip
It is the embedding example from boost, with an "import sha" statement added inside it. sha depends on some dynamically loaded code. When I try to run it, it says:
ImportError: /usr/lib/python2.3/lib-dynload/sha.so: undefined symbol: Py_FindMethod
You should post this question on comp.lang.python; it's really not a Boost-related problem. I'm sure someone there knows how to deal with it. -- Dave Abrahams Boost Consulting www.boost-consulting.com
My problem means boost.build doesn't know how to properly link my embedded Python program. I can add that same line "import sha" to /libs/python/test/embedding.cpp, build it with 'bjam embedding', and the test fails to run properly. According to the ld manual page I need to use --export-dynamic to expose symbols coming from static parts of my binary (like the static libpython boost.build likes to link to) to dynamic libraries like imported python modules. Or I can just dynamically link libpython I haven't sufficiently decoded boost.build to figure out how to change the library search path to prefer the dynamically loaded Python library xor add the linker option --export-dynamic, I would prefer to just dynamically link libpython and it would be nice to keep boost's handy Python version finder. Thanks for any help, Daniel Holth
participants (2)
-
Daniel Holth -
David Abrahams