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

Eric Jardim ericjardim at gmail.com
Wed Aug 31 16:31:29 CEST 2005


Hi,

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

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.

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."

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 code I am trying is:

> using namespace boost::python;
> 
>  object main_module((
>  handle<>(borrowed(PyImport_AddModule("__main__")))));
> 
>  object main_namespace = main_module.attr("__dict__");
> 
>  // Define the derived class in Python.
>  // (You'll normally want to put this in a .py file.)
>  python::handle<> result(
>  PyRun_String(
>  "import Qt\n"
>  "from Qt.Gui import QPushButton\n"
>  "print QPushButton\n",
>  Py_file_input, main_namespace.ptr(), main_namespace.ptr())
>  );
>  // Result is not needed
>  result.reset();
> 

I also call PyInitialize first.

Thanks for any help,

[Eric Jardim]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20050831/728e2d0e/attachment.htm>


More information about the Cplusplus-sig mailing list