0

I want to use c++ numerical recipes on my python script but I am having some issues compiling some stuff in the Boost Python Libraries. Specificly I want to expose the amoeba function to python. I use Make rather than BJam. This is what I get when I try to compile:

costantinoagnesi@costantino-HP-Pavilion-dv5-Notebook-PC:~/Desktop/Boost Python Test$  make
g++ -I/usr/include/python2.7 -I/usr/include -fPIC -c amoeba_py.C
In file included from /usr/local/include/boost/python/object/make_instance.hpp:10:0,
               from /usr/local/include/boost/python/object/make_ptr_instance.hpp:8,
               from /usr/local/include/boost/python/to_python_indirect.hpp:11,
               from /usr/local/include/boost/python/converter/arg_to_python.hpp:10,
               from /usr/local/include/boost/python/call.hpp:15,
               from /usr/local/include/boost/python/object_core.hpp:14,
               from /usr/local/include/boost/python/args.hpp:25,
               from /usr/local/include/boost/python.hpp:11,
               from amoeba_py.C:73:
/usr/local/include/boost/python/converter/registered.hpp: In function ‘const boost::python::converter::registration&
boost::python::converter::detail::registry_lookup2(T& (*)()) [with T = double(const NRVec<double>&)]’:
/usr/local/include/boost/python/converter/registered.hpp:94:40:   instantiated from ‘const >boost::python::converter::registration& boost::python::converter::detail::registry_lookup1(boost::type<T>) [with T = double (&)(const NRVec<double>&)]’
/usr/local/include/boost/python/converter/registered.hpp:105:23:   instantiated from const boost::python::converter::registration& boost::python::converter::detail::registered_base<double (&)(const NRVec<double>&)>::converters’
/usr/local/include/boost/python/converter/arg_from_python.hpp:269:99:   instantiated from  ‘boost::python::converter::pointer_arg_from_python<T>::pointer_arg_from_python(PyObject*) [with T = double (*)(const NRVec<double>&), PyObject = _object]’
/usr/local/include/boost/python/arg_from_python.hpp:70:18:   instantiated from ‘boost::python::arg_from_python<T>::arg_from_python(PyObject*) [with T = double (*)(const NRVec<double>&), PyObject = _object]’
/usr/local/include/boost/preprocessor/iteration/detail/local.hpp:43:1:   instantiated from >‘PyObject* boost::python::detail::caller_arity<5u>::impl<F, Policies, Sig>::operator( (PyObject*, PyObject*) [with F = void (*)(NRMat<double>&, NRVec<double>&, double, double (*)(const NRVec<double>&), int&), Policies = boost::python::default_call_policies, Sig = boost::mpl::vector6<void, NRMat<double>&, NRVec<double>&, double, double (*)(const NRVec<double>&), int&>, PyObject = _object]’
/usr/local/include/boost/python/object/py_function.hpp:38:33:   instantiated from ‘PyObject* boost::python::objects::caller_py_function_impl<Caller>::operator()(PyObject*, PyObject*) [with Caller = boost::python::detail::caller<void (*)(NRMat<double>&, NRVec<double>&, double, double (*)(const NRVec<double>&), int&), boost::python::default_call_policies, boost::mpl::vector6<void, NRMat<double>&, NRVec<double>&, double, double (*)(const NRVec<double>&), int&> >, PyObject = _object]’ amoeba_py.C:79:1:   instantiated from here
/usr/local/include/boost/python/converter/registered.hpp:86:7: error: no matching function >for call to ‘register_shared_ptr1(double (*)(const NRVec<double>&))’
/usr/local/include/boost/python/converter/registered.hpp:86:7: note: candidate is:
/usr/local/include/boost/python/converter/registered.hpp:77:3: note: template<class T> void boost::python::converter::detail::register_shared_ptr1(const volatile T*)
make: *** [amoeba_py.o] Error 1

Can someone help me decipher what this error means and perhaps give me some helpful tip to finish my project. It's worth noting that the classic Boost Python example compiles just fine. Thank you!

Here's the offending text: (lines 73-79)

#include <boost/python.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE(amoeba)
{
     def("amoeba", NR::amoeba);
}
  • Can you please post the offending section(s) of code from *amoeba_py.C*? I see lines 73 and 79 mentioned in the error message, what's at those lines? – Praetorian Oct 24 '13 at 22:46
  • @Praetorian OK! I added the offending code. Thanks ps if you also need the numerical recipes function you can find it here: [link]http://www2.units.it/ipl/students_area/imm2/files/Numerical_Recipes.pdf). – user2917789 Oct 24 '13 at 22:57
  • It looks like the link posted in the answer below explains the problem. Your `amoeba` function takes a function pointer, and to expose it to python you'll need to create a wrapper for it. – Praetorian Oct 24 '13 at 23:50

2 Answers2

0

I suspect you're having a similar problem to the guy who asked this question. Are you passing a function pointer as an argument in your C++ code? If so, you can't do that in Python -- see the answer as to why.

Community
  • 1
  • 1
Christian Ternus
  • 8,406
  • 24
  • 39
0

You forgot reference operator. Thus the def is getting parameter type double (*)(const NRVec<double>&) instead of const volatile T* it expects.

Your code ought to look like this:

BOOST_PYTHON_MODULE(amoeba)
{
     def("amoeba", &NR::amoeba);
}
vartec
  • 131,205
  • 36
  • 218
  • 244