From what I gather, a good way to do this is to use the Boot.Python library, like this simple example; please don't recommend alternatives like Cython as a solution. But when I try to use boost::python data types, my cpp file won't build.
example_boost.cpp:
#include <boost/python.hpp>
#include <boost/python/numpy.hpp>
#include <iostream>
namespace bpy = boost::python;
namespace bnp = boost::python::numpy;
void do_stuff(const bnp::ndarray& input_array) {
...
};
/*
* This is a macro Boost.Python provides to signify a Python extension module. This enables me to import example_boost.cpp and call do_stuff() within a Python file.
*/
BOOST_PYTHON_MODULE(crf) {
// Expose the functions
boost::python::def("compute_factor_out_msgs", compute_factor_out_msgs);
}
Running make...
Undefined symbols for architecture x86_64:
"boost::python::converter::object_manager_traits<boost::python::numpy::ndarray>::get_pytype()", referenced from:
boost::python::detail::caller_arity<1u>::impl<OutMessages (*)(boost::python::numpy::ndarray const&), boost::python::default_call_policies, boost::mpl::vector2<OutMessages, boost::python::numpy::ndarray const&> >::operator()(_object*, _object*) in example_boost.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [example_boost.so] Error 1
Notes:
makewas successful if I don't use thebpyandbnptypes, so my Makefile is correct.- I have Boost v 1.63.0 installed via homebrew, on Mac OSX El Capitan
- Using C++ 11 and Python 2.7
makewas successful if I don't use thebpyandbnptypes, so my Makefile is correct. Nope, it misses the linker flags to the libraries providing the symbols inbpyandbnp.