Boost logo

Boost Users :

Subject: [Boost-users] [Python] Undefined symbol in extension library with python 3
From: Vivek (vivek_at_[hidden])
Date: 2011-04-27 23:41:53

I compiled and installed boost 1.46.1 from source recently using:

$ ./ --with-python-version=3.1
$ sudo ./bjam -j4 install

I then created the following trivial python extension:

#include <boost/python.hpp>

struct mystruct {
    int i;

    using namespace boost::python;
        .def_readwrite("i", &mystruct::i)

and compiled and ran it, but got an undefined symbol error:

$ g++ -shared question.cpp -I/usr/include/python3.1 -lboost_python3
$ python3
Python 3.1.2 (release31-maint, Sep 17 2010, 20:34:23)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import test
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ./ undefined symbol:

ldd confirms the missing symbol:

$ ldd -r => (0x00221000) => /usr/local/lib/
(0x00a3d000) => /usr/lib/ (0x0022b000) => /lib/ (0x00960000) => /lib/ (0x00316000) => /lib/ (0x004b8000) => /lib/ (0x00cf2000) => /lib/ (0x00be4000) => /lib/ (0x005d3000) => /lib/ (0x00489000)
/lib/ (0x00fd5000)
undefined symbol: PyExc_ImportError
undefined symbol: PyProperty_Type
... snip ...
*undefined symbol: _ZN5boost6python6detail11init_moduleEPKcPFvvE (./
undefined symbol: _Py_NoneStruct (./
undefined symbol: PyLong_FromLong (./
undefined symbol: PyLong_Type (./

However nm confirms that the symbol exists in

$ nm /usr/local/lib/ | c++filt | grep init_module
00031a00 T boost::python::detail::init_module(PyModuleDef&, void (*)())

I've tried running ldconfig to update the library cache, as well as
compiling the extension with -lpython3.1, but no luck.

Ideas appreciated,


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at