Using Boost 1.63.0, I've coded up the following:
vectors.cpp
/* Boost/Python headers */
#include<boost/python/module.hpp>
#include<boost/python/def.hpp>
#include<boost/python/extract.hpp>
#include<boost/python/numpy.hpp>
#include<cmath>
using namespace boost::python;
namespace np = boost::python::numpy;
double eucnorm(np::ndarray axis){
const int n = axis.shape(0);
double norm = 0.0;
for(int i = 0; i < n; i++){
double A = boost::python::extract<double>(axis[i]);
norm += A*A;
}
return sqrt(norm);
}
BOOST_PYTHON_MODULE(vectors){
def("eucnorm", eucnorm);
}
I've compiled this using:g++ -shared -fpic -I /usr/include/python2.7 -I /foo/bar/boost_1_63_0 -lboost_python -o vectors.so
And I get the following error upon import:
from vectors import *
ImportError: ./vectors.so: undefined symbol: _ZN5boost6python9converter21object_manager_traitsINS0_5numpy7ndarrayEE10get_pytypeEv
What does this mean, and how do I fix this?
Add:
-lboost_numpy -lboost_python
When you build the .so.
By the way, if you want to find out about such problems at build time (rather than having to try import
in Python): Force GCC to notify about undefined references in shared libraries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With