Linking Boost Python C++

  boost, boost-python, c++, linker, python

I am running in an issue which I can not resolve. I am trying to get a simple Boost Python example to run. I am compiling on Ubuntu 18.04

  1. Downloaded boost_1_66_0.tar.bz2 into /home/user/Tools directory
  2. tar –bzip2 -xf boost_1_66_0.tar.bz2 creates dir /home/user/Tools/boost_1_66_0
  3. cd into /home/user/Tools/boost_1_66_0
  4. ./bootstrap.sh –with-python-version=3.6 –with-libraries=all
  • python3.6 system interpreter in /usr/bin/python3
  1. sudo ./b2 install *to install boost into /usr/local/
  • Compiles without error all targets
  1. cd /home/user/Tools/boost_1_66_0/libs/python/example/tutorial

  2. c++ -fPIC -I /usr/include/python3.6 -l boost_python3 -l boost_system hello.cpp -o hello_ext.so

I do not compile into shared lib, , to see if there are some errors in the linking steps (so please do not complain about the missing main in the error msg). Everything compiled correct, but still c++ cannot resolve some references of the boost python:

(.text+0x20): undefined reference to `main'
/tmp/cch74VeS.o: In function `PyInit_hello_ext':
hello.cpp:(.text+0x9a): undefined reference to `boost::python::detail::init_module(PyModuleDef&, void (*)())'
/tmp/cch74VeS.o: In function `boost::python::type_info::name() const':
hello.cpp:(.text._ZNK5boost6python9type_info4nameEv[_ZNK5boost6python9type_info4nameEv]+0x1f): undefined reference to `boost::python::detail::gcc_demangle(char const*)'
/tmp/cch74VeS.o: In function `boost::python::to_python_value<char const* const&>::operator()(char const* const&) const':
hello.cpp:(.text._ZNK5boost6python15to_python_valueIRKPKcEclES5_[_ZNK5boost6python15to_python_valueIRKPKcEclES5_]+0x1b): undefined reference to `boost::python::converter::do_return_to_python(char const*)'
/tmp/cch74VeS.o: In function `boost::python::to_python_value<char const* const&>::get_pytype() const':
hello.cpp:(.text._ZNK5boost6python15to_python_valueIRKPKcE10get_pytypeEv[_ZNK5boost6python15to_python_valueIRKPKcE10get_pytypeEv]+0xb): undefined reference to `PyUnicode_Type'
/tmp/cch74VeS.o: In function `boost::python::api::object::object()':
hello.cpp:(.text._ZN5boost6python3api6objectC2Ev[_ZN5boost6python3api6objectC5Ev]+0x14): undefined reference to `_Py_NoneStruct'
/tmp/cch74VeS.o: In function `void boost::python::def<char const* (*)()>(char const*, char const* (*)())':
hello.cpp:(.text._ZN5boost6python3defIPFPKcvEEEvS3_T_[_ZN5boost6python3defIPFPKcvEEEvS3_T_]+0x50): undefined reference to `boost::python::detail::scope_setattr_doc(char const*, boost::python::api::object const&, char const*)'
/tmp/cch74VeS.o: In function `boost::python::api::object boost::python::detail::make_function_aux<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> >(char const* (*)(), boost::python::default_call_policies const&, boost::mpl::vector1<char const*> const&)':
hello.cpp:(.text._ZN5boost6python6detail17make_function_auxIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS4_EEEENS0_3api6objectET_RKT0_RKT1_[_ZN5boost6python6detail17make_function_auxIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS4_EEEENS0_3api6objectET_RKT0_RKT1_]+0x67): undefined reference to `boost::python::objects::function_object(boost::python::objects::py_function const&)'
/tmp/cch74VeS.o: In function `boost::python::objects::py_function_impl_base::py_function_impl_base()':
hello.cpp:(.text._ZN5boost6python7objects21py_function_impl_baseC2Ev[_ZN5boost6python7objects21py_function_impl_baseC5Ev]+0xb): undefined reference to `vtable for boost::python::objects::py_function_impl_base'
/tmp/cch74VeS.o:(.data.rel.ro._ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE[_ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE]+0x30): undefined reference to `boost::python::objects::py_function_impl_base::max_arity() const'
/tmp/cch74VeS.o: In function `boost::python::objects::caller_py_function_impl<boost::python::detail::caller<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> > >::~caller_py_function_impl()':
hello.cpp:(.text._ZN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEED2Ev[_ZN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEED5Ev]+0x26): undefined reference to `boost::python::objects::py_function_impl_base::~py_function_impl_base()'
/tmp/cch74VeS.o:(.data.rel.ro._ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE[_ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE]+0x10): undefined reference to `typeinfo for boost::python::objects::py_function_impl_base'
/tmp/cch74VeS.o: In function `boost::python::converter::expected_pytype_for_arg<char const*>::get_pytype()':
hello.cpp:(.text._ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv[_ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv]+0x1b): undefined reference to `boost::python::converter::registry::query(boost::python::type_info)'
hello.cpp:(.text._ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv[_ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv]+0x32): undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
collect2: error: ld returned 1 exit status

Source: Windows Questions C++

LEAVE A COMMENT