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

Johan Lundberg
  • 26,184
  • 12
  • 71
  • 97
Vicente Botet Escriba
  • 4,305
  • 1
  • 25
  • 39
  • 4
    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. – alfC Nov 04 '11 at 00:14
  • They will work if you define the macro : ``#define BOOST_NO_CXX11_SCOPED_ENUMS`` before the include of ``filesystem.hpp`` – Gabriel Sep 24 '13 at 09:22

5 Answers5

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
Vicente Botet Escriba
  • 4,305
  • 1
  • 25
  • 39
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.

Sean
  • 9,888
  • 4
  • 40
  • 43
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.

Gabriel
  • 8,990
  • 6
  • 57
  • 101
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.

Pieter
  • 2,822
  • 18
  • 17
3

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

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

Bunkar
  • 651
  • 5
  • 4