I am fairly new to the boost c/c++ library. I downloaded boost library and build the library.
I created a very simple python library in c++ using boost interface (actually it is example code given in the documentation). I built it into a dll file. In the documentation it reads that this dll is exposed to python and they just show the import function in python and include the created library. I don't understand how to expose that dll to python and load the library inside in tradition ('import') manner. In case if you wanna look at the code then here it is:
#include <boost/python.hpp>
char const* greet()
{
return "hello, world";
}
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
Please help I really want to build applications with c/c++ and python. I simply want to use hello_ext as:
>>>import hello_ext
>>>print hello_ext.greet()
Thank you.
I built it into a dll file. In the documentation it reads that this dll is exposed to python and they just show the import function in python and include the created library. I don't understand how to expose that dll to python and load the library inside in tradition ('import') manner.
You need to put that shared library into the module search path. There are a few ways to achieve that.
One is:
import sys
sys.path.append("<directory-where-hello_ext-module-resides>")
import hello_ext
Your shared library should be called hello_ext.dll
.
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