2

I am having problems when linking the following code:

#include <boost/python.hpp>
#include <boost/python/numpy.hpp>

BOOST_PYTHON_MODULE (MyLibrary)
{

    Py_Initialize() ;
    boost::python::numpy::initialize() ;

    ...

}

which returns:

undefined reference to `boost::python::numpy::initialize(bool)'

I am using Boost 1.68 with Python 3.6, compiled as follows:

./bootstrap.sh --with-python=/usr/bin/python3 --with-python-version=3.6 --with-python-root=/usr/lib/python3.6
./b2 --with-python link=shared install

And I am linking using:

/usr/bin/c++ -shared
-o MyLibrary.so
MyLibrary.cpp.o
-L/usr/local/lib
-lpython3.6m
/usr/local/lib/libboost_python36.so

Any idea...?

2
  • 1
    Numpy routines are built into a separate library e.g. libboost_numpy.so. Check if that has actually been built, i believe it's built automatically if it (and the development headers etc) are installed in your python environment. Commented Sep 19, 2018 at 22:01
  • Do you know what headers are supposed to be present? No libboost_numpy.so has been built in my case, and I didn’t find any option or documentation in b2. Commented Sep 19, 2018 at 22:36

1 Answer 1

4

The solution was to install the python3-numpy package first, otherwise libboost_numpy.so does not get generated.

End of the story!

Sign up to request clarification or add additional context in comments.

2 Comments

you're a legend lucas, very helpful
Thanks! This pointed me in the right direction. This seemed to resolve the problem in my case on Ubuntu 22.04: sudo apt install --reinstall libboost-numpy-dev libboost-numpy1.74-dev libboost-numpy1.74.0 python3-numpy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.