Extending C++ with Boost Python
Lately I have been messing around with the boost python library to extend c++ (Being able to instantiate C++ over python). Since I wanted to create my own Makefiles I wanted to avoid using bjam. To build shared objects you can do it as follows.
Boost Python Hello World
g++ -shared -fPIC -o hello_ext.so hello.cpp -I/usr/local/include/boost/python -I/usr/local/include/python2.6 -lboost_python
hello.cpp
// Copyright Joel de Guzman 2002-2004. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
// Hello World Example from the tutorial
// [Joel de Guzman 10/9/2002]#include
#includechar const* greet()
{
return “hello, world”;
}BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def(“greet”, greet);
}
hello.py
# Copyright Joel de Guzman 2002-2007. Distributed under the Boost
# Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
# or copy at http://www.boost.org/LICENSE_1_0.txt)
# Hello World Example from the tutorialimport hello_ext
print hello_ext.greet()
Comentarios
Hace tiempo, trasteando con las