Python extension building with boost

Posted by user1544053 on Stack Overflow See other posts from Stack Overflow or by user1544053
Published on 2012-11-17T16:57:58Z Indexed on 2012/11/17 16:59 UTC
Read the original article Hit count: 198

Filed under:
|
|
|

Hey guys I'm fairly new to 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.

© Stack Overflow or respective owner

Related posts about c++

Related posts about python