Wednesday, 10 July 2013

Compiling BOOST with custom GCC location

Compiling BOOST on our shared cluster running CentOS 5 is always a pain in the neck. The default GCC version is 4.1, so compiling programs with just the default GCC is not always the best choice.
I was trying to compile a program that depends on BOOST, and figuring out how to specify non-default compilers to BOOST took me a while to figure out.

Download your version of BOOST and untar:

tar xjf boost_1_52_0.tar.bz2

Find the user-config.jam file (this is where the magic happens) and edit:

cd boost_1_52_0
vim tools/build/v2/user-config.jam

Add the line corresponding to your C++ compiler (In my case G++ 4.4). The user-config.jam file loosk something like:

# ------------------
# GCC configuration.
# ------------------

# Configure gcc (default version).
# using gcc ;
# Configure specific gcc version, giving alternative name to use.
# using gcc : 3.2 : g++-3.2 ;
using gcc : 4.4 : /usr/bin/g++44 ;

The syntax is:

using <toolset name> : <version> : <executable> ;

See more info here:

Now bootstrap BOOST as you normally would:

./ --prefix=/opt/boost_1_52_0_gcc44

And compile! Use the -d2 option to up the debug level of b2, so you can see the actual compile command (and check that b2 is using the correct compiler):

./b2 -d 2
./b2 install

Tell your mother of that awesome blog post you just read.

No comments:

Post a Comment