How to get BOOST working on XP and Visual C++ 2005

O

Osiris

My experiences with BOOST on Windows XP and Visual C++ 2005

I'm new to Python.
I built software in more than ten other computer languages. I'm not
sure if that is not a handicap, when reading documentation of a system
like BOOST.
However:
It took me more than four full working days to get a Python/C/C++
'hello world!' program to work. There is a lot of documentation, but
somehow it did not 'click' with my previous experience. I think the
doc was written by very, very capable C++ and Python programmers, who
forgot how the world was before they got involved with Python.
A teacher/doc writer should never forget that, I think.
Mind you: the documentation is all there. Stressing the word ALL.
There is a lot of documentation. Which makes it very difficult to
choose the right piece.

My project is, to use old and tested and stable and error-free C-code
in a website built with Zope (www.zope.org) and Plone (www.plone.org).
So I think, C-code can be wrapped in some C++ and then, with the help
of Boost, be called from Python. Python is important when using Plone.

So let me summarize what I found out.

BOOST is a system to combine Python and C++. Call C++ compiled code
from Python, which is interpreted.
In the end, BOOST is a sort of "make" facility like found on Linux
(and Windows). In Boost it is called, not 'make.exe', but 'bjam.exe'.
You define a list of operations, which bjam executes for you. It runs
from the command line (I grew up, IT-wise, in the DOS-era. Hurray), it
has no GUI-like Windows front-end.

So the first step is to get bjam.exe from the net. There are two ways
to get it:
1. download a ready-to-run bjam.exe from
http://downloads.sourceforge.net/boost/boost-jam-3.1.13-1-ntx86.zip?modtime=1149717367&big_mirror=0.
In the zip you will find the bjam.exe, which you put it in a place
where the system can always find it, like in c:\, or somewhere else in
the system's PATH.
2. download the sources for bjam.exe and build it yourself:
http://downloads.sourceforge.net/boost/boost-jam-3.1.13.zip?modtime=1149717465&big_mirror=0
.. I recommend not to do this, if you don't have to. And on Windows XP,
you don't have to. You could spend a lot of time to figure out how to
set up things before even building bjam.exe.

The second step is to get Boost libraries. These are for combining
with your C/C++ source, so Python can access the C/C++ code.
You download this stuff from Sourceforge:
http://downloads.sourceforge.net/boost/boost_1_33_1.zip?modtime=1133816391&big_mirror=0
It is a zip file that you unzip to a convenient location. I unzipped
to D:\ so I got a folder named d:\boost_1_31_1 with all the stuff in
it. I renamed this folder to d:\boost, to get rid of all the messy
version numbers.
To build the boost libraries from these sources, you need bjam, and
bjam makes use of your C/C++ compiler. In my case that was Microsoft
Visual C++ 2005, which has version number 8.0.
Now you have to make bjam and Visual C++ acquainted with the location
of supporting software. I made a BAT file to do this. This is what is
in that .BAT file, named SET.BAT and which I put in D:\boost:

d:
cd \boost
call e:\msvc\vc\vcvarsall.bat
set VC80_ROOT=e:\msvc\vc
set TOOLS=vc-8_0
set PYTHON_ROOT=c:\python24
set PYTHON_VERSION=2.4

I explain:
e:\msvc is where I installed my Visual C++ system. The Microsoft
default location would be something like C:\Microsoft Visual C 2005\
etc, but I preferred D:\msvc.
Change the SET.BAT file as needed .
My IDLE (http://www.python.org/idle/) Python 2.4 is in C:\python24
The value 'vc-8_0' denotes the boost identification of my MS Visual
C++ system. If you use an other C++ system, it must be something else
(see http://www.boost.org/more/getting_started.html)

Now start a DOS box: Click the Start button in the lower left corner,
click on "run" and type "cmd".
There you switch to D:\ and change directory to \BOOST.
Execute the SET.BAT.
Then just type "bjam" (the system will find the program bjam itself,
because it is in the PATH)

Now get a lot of coffee, because the build will take a LONG time,
maybe 15 minutes or more.
You will see a lot of cpp-compiling and linking going on and some
warnings about 'deprecation', which are irrelevant.

When finished, keep the DOS box open. You will find BOOST stuff in
C:\boost, the default location for the compiling results.

Now try out an example. In the DOS box, go to
D:\boost\libs\python\example\tutorial, where you find a 'hello'
example and a Jamfile. Jamfile's are what a makefile is for make.: a
script for bjam to build all the 'hello' stuff needed for python.

Type 'bjam' again, and take a smaller amount of coffee. The system
will build the 'hello' stuff for you. Do not be alarmed about bjam
finding 1200+ 'targets' and rebuilding 40 of them, when only needing
to compile hello.cpp…. this is normal behaviour.

When bjam has finished, you will find 'hello' stuff in the
unbelievably deep folder
D:\boost\libs\python\example\tutorial\bin\tutorial\hello.pyd\vc-8_0\debug\threading-multi
Really. I don't know why this must be so deep.
And some Boost stuff in the even more deep folder
D:\boost\libs\python\example\tutorial\bin\boost\libs\python\build\boost_python.dll\vc-8_0\debug\threading-multi

Find the hello.pyd and boost_python.dll and move them to the folder
where yout python.exe is, in my case c:\python24.

Now you go to
file:///D:/boost/libs/python/doc/tutorial/doc/html/python/hello.html
which is part of the Boost download. and read the page.
That should get you on your way.
Of course, now it might be beneficial to you to start reading the
other documentation on
http://www.boost.org/more/getting_started.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top