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.