Question

I don't know how to build Boost with C++0x compilers. Which option must be given to bjam? Should the user.config file be modified?Can someone help me?

Best, Vicente

Was it helpful?

Solution

I have found the answer. I was waiting for a features something like 'std' and call it as follows:

bjam std=0x

but currently we need to use the low level variables cxxflags and add the specific compiler flags. For example for gcc we can do

bjam toolset=gcc cxxflags=-std=gnu++0x

Other compilers will need a different setting.

Waiting for a new Boost.Build feature, you can also define your own toolset as follows: Add the user.config or site.config file

using gcc
   : std0x
   : "/usr/bin/g++" # your path to the C++0x compiler
   : <cxxflags>-std=gnu++0x
   ;

And now call as

bjam toolset=gcc-std0x

OTHER TIPS

Use something like this:

./bootstrap.sh --with-toolset=gcc --prefix=/usr/local

./b2 -j12 toolset=gcc variant=release link=shared threading=multi address-model=64 cxxflags=-std=c++11 install 

The -j12 is for parallel (12 threads) build use -std=c++11 for better compatibility and -std=gnu++11 for the gnu extensions (only for gcc)

if boost::mpi is not build (see the output of above command) -> edit the user-config.jam

if you want to build only certain components: add:

--with-libraries=system,thread,serialization

for example

Here is an adapted script from my framework from travis (adjust ROOT_PATH):

BOOST_DOWNLOAD_URL="http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.tar.bz2/download"
BOOST_BUILD=${ROOT_PATH}/boostBuild
mkdir -p ${BOOST_BUILD}
wget --no-verbose --output-document="${ROOT_PATH}/boost.tar.bz2" "$BOOST_DOWNLOAD_URL"
cd ${BOOST_BUILD}
tar jxf "${ROOT_PATH}/boost.tar.bz2" --strip-components=1 -C "${BOOST_BUILD}"
./bootstrap.sh --with-toolset=gcc --with-libraries=system,thread,serialization,filesystem,chrono,atomic,date_time
sudo ./b2 -j12 toolset=gcc threading=multi link=shared release install

which installs into /usr/local.

To compile using clang, use the cxxflags and linkflags:

./b2 \
    ...
    cxxflags="-std=c++0x -stdlib=libc++" \
    linkflags="-stdlib=libc++" \
    ...

Passing a -v to cxxflags is also helpful when debugging.

I came across an article for compiling Boost using clang: http://blog.llvm.org/2010/05/clang-builds-boost.html. It might be possible to adapt the changes proposed there for compiling Boost using Boost.Jam to your favorite C++0x compiler.

Also, you can change compilation flags for one file like this:

exe test : test.cpp : <cxxflags>-std=gnu++0x ;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top