Thursday, June 14, 2007

Getting Boost Python working under Cygwin

Having trouble getting Boost Python working under gcc/cygwin/windows? I did. And I found the documentation not that great, so here's a step by step guide to what I did to get it working. But for those of you in a hurry, here's the short method:



  1. Download boost from http://sourceforge.net/project/showfiles.php?group_id=7586, decompress, and copy to whereever you want it

  2. Download boost jam (bjam) from http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=72941, decompress, and copy to whereever you want it

  3. Add bjam to your path (Start, Control Panel, System, Advanced, Environment Variables) from whereever you put it in step 2

  4. Make sure you have gcc and python installed from cygwin setup, not just windows python from the python website

  5. Edit /boost_1_34_0/tools/build/v2/user-config.jam from wherever you decompressed boost to in step 1. Add the line:
    using python : 2.5 : c:\\cygwin\\bin\\python2.5 : : : cygwin ;

  6. Start a cygwin shell and change to where you put boost /libs/python/example/quickstart. In this directory type bjam toolset=gcc --verbose-test and everything should work

Now for how I did it, which will hopefully help a few people googling for the error messages that I got.


I downloaded boost and decompressed, and following the instructions at http://www.boost.org/libs/python/doc/building.html#configuring-boost-build i also downloaded and installed bjam. So far, so good. On trying "bjam toolset=gcc --verbose-test" in the /libs/python/example/quickstart directory I got the following message:




$ bjam toolset=gcc --verbose-test

Jamroot:17: in modules.load

rule python-extension unknown in module Jamfile.

~/boost_1_34_0/tools/build/v2/build\project.jam:312: in load-jamfile

~/boost_1_34_0/tools/build/v2/build\project.jam:68: in load

~/boost_1_34_0/tools/build/v2/build\project.jam:170: in project.find

~/boost_1_34_0/tools/build/v2\build-system.jam:237: in load

~/boost_1_34_0\libs\python\example\quickstart\..\..\..\tools\build\v2/kernel\modules.jam:261: in import ~\boost_1_34_0\libs\python\example\quickstart\..\..\..\..\tools\build\v2/kernel/bootstrap.jam:132: in boost-build

~\boost_1_34_0\libs\python\example\quickstart\boost-build.jam:7: in module scope


Oh dear. A bit of googling found this page http://svn.boost.org/trac/boost/ticket/986 which told me I needed to add the line "using python ;" to the user-config.jam file. On trying to build again, I hit lots of compiler errors which started like:




In file included from C:/Python24/Include/Python.h:82,
from ../../../../boost/python/detail/wrap_python.hpp:142,
from ../../../../boost/python/detail/prefix.hpp:13,
from ../../../../boost/python/class.hpp:8,
from extending.cpp:5:
C:/Python24/Include/intobject.h:41: error: `__int64' does not name a type
In file included from C:/Python24/Include/Python.h:84,
from ../../../../boost/python/detail/wrap_python.hpp:142,
from ../../../../boost/python/detail/prefix.hpp:13,
from ../../../../boost/python/class.hpp:8,
from extending.cpp:5:
C:/Python24/Include/longobject.h:37: error: `__int64' was not declared in this s
cope
C:/Python24/Include/longobject.h:39: error: `__int64' does not name a type
C:/Python24/Include/longobject.h:40: error: `__int64' does not name a type
C:/Python24/Include/longobject.h:41: error: `__int64' does not name a type
In file included from ../../../../boost/python/converter/arg_to_python.hpp:17,
from ../../../../boost/python/call.hpp:15,
from ../../../../boost/python/object_core.hpp:12,
from ../../../../boost/python/object/class.hpp:10,
from ../../../../boost/python/class.hpp:13,
from extending.cpp:5:
../../../../boost/python/converter/builtin_converters.hpp:111: error: missing `>
' to terminate the template argument list
../../../../boost/python/converter/builtin_converters.hpp:111: error: template a
rgument 1 is invalid



This was confusing.



Eventually http://lists.boost.org/boost-build/2006/05/13906.php gave me the hint I needed. I had a windows python 2.4 installation, and boost python seemed to need cygwin's python to work under cygwin. So using cygwin setup I installed python (and updated gcc) for good measure. Unfortunately still no luck. Finally the boost instructions at http://www.boost.org/libs/python/doc/building.html#configuring-boost-build gave the final hint.

bjam toolset=gcc --debug-configuration --verbose-test revealed that boost was still picking up my old python from the registry. By doing of expressly putting the new cygwin python in /boost_1_34_0/tools/build/v2/user-config.jam , by modifying my "using python ;" line so it read "using python : 2.5 : c:\\cygwin\\bin\\python2.5 : : : cygwin ;" everything started working.

A happy ending...