[C++-sig] Boost.Python embedded doubt

Stefan Seefeld seefeld at sympatico.ca
Wed Aug 31 16:57:28 CEST 2005


Eric Jardim wrote:
> Hi,
> 
> For QtDesigner integration, I need to embedded Python extended classes 
> exposed back to C++. So I started with the tutorial and the Boost.Python 
> test example. The test is ok.

Please note that I recently added some functions specifically to make
embedding more convenient. There are three new functions: 'exec', 'exec_file',
and 'import'.
I'm not sure where to look for the updated reference manual, as the official
one doesn't contain my additions yet.
In the process I removed the (outdated) 'embedding' test and replaced it
with 'exec', which may be useful as an example. FWIW.

> Then I changed the example to my needs, and tryed to load the Qt module. 
> The program compile and run, but output:
> Traceback (most recent call last):
>   File "<string>", line 1, in ?
>   File "/u/cwd7/devel/boost/python-qt4-0.0.3rc1/Qt/__init__.py", line 8, 
> in ?
>     import dl
> ImportError: /g0dv/Bin/Linux/python/lib/python2.3/lib-dynload/dl.so: 
> undefined symbol: _Py_NoneStruct
> 
> This error happens inside the PyRun_String function. I have commented 
> the line of the "ld" module import, and it complain about another 
> symbol. It does not look like a "dl" problem, but a linking problem.

As your C++ application now acts as the python interpreter itself, it
has to provide all the symbols from the python runtime.

> Reading the tutorial,
> http://www.boost.org/libs/python/doc/tutorial/doc/html/python/embedding.htm
> it says: "To be able to use embedding in your programs, they have to be 
> linked to both Boost.Python's and Python's static link library."

I don't think so. But in the past only the static python library was provided.

> Is it really necessary to both the libs be static? I then (curiously) 
> tried to link with the boost_python library dynamically and it 
> complained about another (thrid Py~) symbol.
> 
> I am building this app with Qt "qmake". I do not use bjam, because I 
> need specific precompiling for Qt (easyly done by qmake). But this 
> should not be so complex, shoud it? I am just using simple:
>> >> -L/path/to/python/lib/python2.3/config -lpython2.3 
> -L/path/to/boost/lib -lboost_python-static -lutil
> 
> Am I missing something? Do I have to do anything else?

The missing symbols are provided by the python runtime, so linking
to the python library (static or dynamic shouldn't matter) should
do the trick.

Regards,
		Stefan



More information about the Cplusplus-sig mailing list