How to build Boost with C++0x support?
Asked Answered
A

5

42

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

Aldarcie answered 22/5, 2010 at 10:20 Comment(2)
Wanted to note that as of boost 1.48 and gcc-4.5, compiling with c++0x is necessary for libraries such as boost::filesystem. Otherwise functions like copy_file are not found at linking.Scuppernong
They will work if you define the macro : #define BOOST_NO_CXX11_SCOPED_ENUMS before the include of filesystem.hppFumigant
A
44

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
Aldarcie answered 24/5, 2010 at 8:50 Comment(2)
With newer versions of boost it is ./b2 toolset=gcc cxxflags=-std=gnu++0x. With newer versions of gcc, use -std=gnu++11Mirandamire
With newer versions, you can use std=c++11 if you don't want to enable the GNU extensions.Kurrajong
L
12

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.

Lucubration answered 21/4, 2012 at 17:27 Comment(0)
F
12

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.

Fumigant answered 24/9, 2013 at 9:21 Comment(0)
S
3

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.

Symphonious answered 24/5, 2010 at 7:57 Comment(1)
Hi, I don't see nothing in this page related to c++0x. Please could you clarify your response?Aldarcie
E
3

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

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

Euclid answered 29/1, 2011 at 17:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.