[C++-sig] CMake and getting starting with boost.python

Braddock Gaskill braddock at braddock.com
Fri Jun 29 12:03:49 CEST 2007


Yesterday I became a boost.python user, after years of heavy SWIG usage.
I would have started using boost.python years ago except for the bjam
learning curve.  I spent hours TRYING on multiple occasions, but got lost
every time trying to get the page one example to build with bjam.

Here is how to build the "greet" example with a four line CMake file:

cat >>CMakeLists.txt <<EOF
LINK_LIBRARIES(boost_python)
INCLUDE_DIRECTORIES("/usr/include/python2.5")
LINK_DIRECTORIES("/usr/lib/python2.5") # Not needed?
ADD_LIBRARY(hello SHARED hello.cpp)
EOF

You WILL have to `mv libhello.so hello.so` after building.

Works for me under Ubuntu Linux 6.10 after
apt-get install cmake python2.5-dev boost-python-dev
cmake
make
mv libhello.so hello.so

ipython
In [1]: import hello
In [2]: hello.greet()
Out[2]: 'hello, world'

Boost.Python has been a joy to learn and use since I got past bjam.
I had a moderately large API wrapped in just my first couple hours of
learning (less time than I spent messing with bjam).

Any additional advice for using CMake to build boost.python?

Braddock Gaskill





More information about the Cplusplus-sig mailing list