libboost_python3.so.1.56.0: undefined symbol: PyClass_Type libboost_python3.so.1.56.0: undefined symbol: PyClass_Type python-3.x python-3.x

libboost_python3.so.1.56.0: undefined symbol: PyClass_Type


As noted in this answer:

PyClass_Type is is part of the Python 2 C API and not part of the Python 3 C API. Hence, the Boost.Python library was likely built against Python 2. However, it is being loaded by a Python 3 interpreter, where the PyClass_Type is not available.

The exact procedure used to produce libboost_python3.so is not presented, so I can only speculate a non clean build, such as building Boost.Python with Python2, then reconfiguring bootstrap with Python3, and then building Boost.Python with the Python2 object files. Regardless, verify a clean build of Boost.Python with Python3.

$ ./bootstrap.sh --with-python=/usr/bin/python2...Detecting Python version... 2.7$ ./b2 --with-python --buildid=2 # produces libboost_python-2.so$ ./bootstrap.sh --with-python=/usr/bin/python3 --with-python-root=/usr...Detecting Python version... 3.3$ ./b2 --with-python --buildid=3noclean # produces libboost_python-3noclean.so$ ./b2 --with-python --clean$ ./b2 --with-python --buildid=3 # produces libboost_python-3.so$ nm -D stage/lib/libboost_python-2.so | grep PyClass_Type                 U PyClass_Type$ nm -D stage/lib/libboost_python-3noclean.so | grep PyClass_Type                 U PyClass_Type$ nm -D stage/lib/libboost_python-3.so | grep PyClass_Type

As expected, libboost_python-2.so references the PyClass_Type symbol. Additionally, the libboost_python-3noclean.so contains a reference to PyClass_Type as it was built with libboost_python-2.so's object files. With a clean build, libboost_python-3.so should not contain a reference to PyClass_Type.