Building Boost::Python
19.10.2010
I want to use some script language to script entities in my thesis. The entity system itself is completely independent of any script engine, so using any engine is possible. I tried many different scripting languages, e.g. AngelScript or Lua, some of them do not have functions I want, with others I would spent ages exposing C++ classes to scripts. A lot of them I did not manage to compile even after trying for two hours. I end up with Boost::Python.
Boost is a group of C++ libraries, one of them is Boost::Python. Boost is heavily based on the template metaprogramming, so most of the libraries must not be built. However Boost::Python is one of the exceptions.
First I downloaded the boost source code from its homepage. It is also possible to download binaries but they did not work for me. Boost is using its own building system called bjam. Bjam can be used with many different compilers, I used MinGW 4.41. First you need to build Bjam itself. I did that using bootstrap.bat from a command line including mingw argument:
c:\boost\> bootstrap.bat mingw
You need to have the compiler in your PATH system variable. Bjam was build without any problems.
Now I tried to build Boost::Python using bjam:
c:\boost\> bjam --toolset=gcc --with-python
but it wasn't working. It displayed a warning that Python is not configured and autoconfiguration failed. I tried to set PYTHON_VERSION and PYTHON_ROOT variables with no effect. Than I tried different versions of boost and MinGW and keep trying for hours. Nothing worked. In the end I decided to not use the bjam building tools but compile the library directly in my IDE - CodeLite. I created a new static library project, add all the source code files of Boost::Python and set compiler and linker as you see on the following images:

In the preprocessor field there is BOOST_PYTHON_STATIC_LINK;BOOST_PYTHON_USE_GCC_SYMBOL_VISIBILITY;BOOST_PYTHON_SOURCE

And it compiled without problems, creating the static library which I can link to my program.
© GameDev.sk 2010