[python] a lot of hassle getting started with embedding and vc8
Hi folks! Probably someone with some hints on how to fix this. I may have overlooked portions of the doc ... Status: boost_1_36_beta installed using bjam for vc8/SP1 against python-2.5.2; python test suite shows no failure. Trying to embed boost::python/Python in a Visual Studio 2008 project: I managed to compile some code in debug mode (linking to python25.lib release mode). The embedded python interpreter (using the precompiled version of python-2.5.2) throws an exception even on statements like "a=2", having "error_already_set", but PyErr_Print(); does not show a message, neither in Debugger nor after calling the executable from the command line. This is odd. So it is time for a debug session - which is where true trouble begins: fetch python source code, compile with vc8 in order to create python25_d.lib and friends. Now what I really want is a *debug* executable with *statically* linked python and boost_python, so I tell it to the boost library by defining BOOST_DEBUG_PYTHON and BOOST_PYTHON_STATIC_LIB. Defining BOOST_PYTHON_STATIC_LIB is necessary to have auto linker link to the static boost_python libs (libboost_python-vc80-mt-sgd.lib) [see http://thread.gmane.org/gmane.comp.lib.boost.user/38461/focus=38600] but has a nasty side effect: Now the compiler decides python_25.lib has to be linked to rather than python25_w.lib. OUCH! I digged into all headers (also using find/grep) to figure out why boost::python now thinks that python25.lib has to be linked into the executable, but could not find the autolinker part for python*.lib. The key part is in boost/python/detail/config.hpp, line 68 // backwards compatibility: #ifdef BOOST_PYTHON_STATIC_LIB # define BOOST_PYTHON_STATIC_LINK # elif !defined(BOOST_PYTHON_DYNAMIC_LIB) # define BOOST_PYTHON_DYNAMIC_LIB #endif I feel uncomfortable about the "backwards compatibility" tag in the comment. So there must be some other way to get around this mess. It all comes down to hinder BOOST_PYTHON_DYNAMIC_LIB to be defined. Looking at [BINARY_DIST]python-2.5.2\include\pyconfig.h - a hand-written version of the python config stuff, there might be some issue with with the "pragma comment(lib" portion ... ================================================== OK, let us revert to dynamic linking then: Using the code from example/quickstart/embedding.cpp I get a <cite> Unhandled exception at 0x00000000 in TestBoostPythonEmbedding.exe: 0xC0000005: Access violation reading location 0x00000000. </cite> triggered by python::object main = python::import("__main__"); calling (*) python::handle<> module(PyImport_ImportModule(n)); // BOOM! but calling PyImport_ImportModule("__main__"); directly succeeds. but stepping into PyImport_ImportModule(n) fails. What's wrong with (*) ? The same game runs without error (!!!!) in release mode. To be honest: I am lost. Any help or hint appreciated. Markus
participants (1)
-
Markus Werle