PintoDoido
PintoDoido

Reputation: 1051

Error importing Boost Python module (function_impl_base9max_arityEv)

I am trying to build a hello world C++ Python extension using boost-python.

I got the following source code from https://www.mantidproject.org/Boost_Python_Introduction:

 // test.cpp
 #include <iostream>
 #include <boost/python.hpp>


 void sayHello()
 {
   std::cout << "Hello, Python!\n";
 }

 BOOST_PYTHON_MODULE(test)  // Name here must match the name of the final shared library, i.e. mantid.dll or mantid.so
 {
    boost::python::def("sayHello", &sayHello);
 }

However, when I try to compile using the following command:

g++ -fPIC -I/usr/include/python3.6m test.cpp -c
g++ -shared test.o -o test.so -I/usr/include/python3.6m -I/lib64/libboost_python3

This command compiles successfully the code and creates a library file test.so.

However, when I try to import the module in python3, I get the following error:

ImportError: /home/yt/C++/test.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv

The link Import Error on boost python hello program seems to suggest the command I used above would solve the problem by adding -I/usr/include/python3.6m and -I/lib64/libboost_python3, but it does not.

What am I doing wrong?

Thanks!

OS: Fedora 29 x86_64

Upvotes: 2

Views: 1003

Answers (1)

PintoDoido
PintoDoido

Reputation: 1051

Thanks guys!

The problem was the linker command. The correct one is:

g++ -fPIC -I/usr/include/python3.6m test.cpp -c

g++ -L /lib64 -shared test.o -o test.so -lpython3.6m -lboost_python3

Now it works on Fedora 29

Upvotes: 1

Related Questions