boost::python examples
These are a few examples on how to use the boost::python library to extend Python with C++ libraries. Some of the are based on the existing tutorial for boost::python from Joel de Guzman. Others are independent.
Prerequisites
general
- CMake (>= 2.8.3)
- Boost (tested with 1.4.2, but should work with >= 1.3.2)
- Python (tested with 2.7, but should work with >= 2.2)
- a C++ compiler for your platform, e.g. GCC or MinGW
The examples should work on Linux, Windows and Mac, but currently have not been tested under Windows.
homebrew
Mac OS X withThere is a special package needed called boost-python. The standard boost package will not be recognized by cmake.
brew install cmake boost-python
Furthermore, for the homebrew python lib to be used, unfortunately the full path has to be given:
cmake -DPYTHON_LIBRARY=/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib ..
Building
- Set the
BOOST_ROOT
environment variable if Boost is installed in a non-standard directory - create a build directory, e.g. directly in the project directory and cd to it:
mkdir build ; cd build
- run
cmake ..
and afterwardsmake
Alternatively, run the provided build.sh
script.
Tests
All examples contain tests, but these only try to run the examples without checking the output. Their purpose is mainly to make sure that compilation works and produces valid Python modules.