I want to provide python interface to my C++ shared library, I am planning to use Boost::python for the same, my C++ code based is huge and divided across headers and implementation files. But all the python::boost examples talks about adding python::boost constructs in cpp files and how to deal this for header files. and Can I have same code based so that I can build both C++ shared library and python modules
Here is a link to a guide on how to use Boost.Python: http://www.boost.org/doc/libs/1_51_0/libs/python/doc/tutorial/doc/html/python/exposing.html
Example using header / implementation structure:
//hpp
#include <boost/python.hpp>
using namespace boost::python;
struct World
{
void set(std::string msg);
std::string greet();
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
}
//cpp
void World::set(std::string msg) { this->msg = msg; }
std::string greet() { return this->msg; }
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