0

I have a third party C ++ API, dynamic library (.so) for Linux with a header file.

My question is, can I directly write a bind file and use boost.python to create python bindings. I tried doing it and I added just one function to my bind.cc file from the API, compiled it and created another .so file. But when I imported this in python3 it threw an ImportError.

Here is my bind file:

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include "tp_api.h"
BOOST_PYTHON_MODULE(bb_api)
{
  using namespace boost::python;
  def("tpGetAPIVersion", tpGetAPIVersion);
}

Build commands:

g++ -O3 -Wall -shared -std=c++11 -fPIC -undefined -I/usr/local/include -L/usr/local/lib -I/usr/include/python3.8 -lboost_python39 -o tp_api python3-config --extension-suffix
bind.cc

This creates: tp_api.cpython-38-x86_64-linux-gnu.so.

And then in python3:

from tp_api import tpGetAPIVersion

throws:

import Error undefined symbol: 
  _ZTIN5boost6python7objects21py_function_impl_baseE.  
martineau
  • 119,623
  • 25
  • 170
  • 301
S.Max
  • 21
  • 3
  • Could you post what you tried? – Codie CodeMonkey Sep 21 '21 at 19:37
  • 2
    Are you linking the boost/python library? I would expect py_function_impl_base to be defined in one of the libraries. See https://www.boost.org/doc/libs/1_77_0/libs/python/doc/html/building/choosing_a_boost_python_library_.html. – Codie CodeMonkey Sep 21 '21 at 19:56
  • Please run `ldd tp_api.cpython-38-x86_64-linux-gnu.so` and add the output to the question. – unddoch Sep 21 '21 at 21:36
  • Yes, libboost.python was not linked. Thanks @CodieCodeMonkey and everyone else, bunch of brilliant people. – S.Max Sep 22 '21 at 07:55

0 Answers0