How to build Boost with C++0x support?
Solution 1
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
Solution 2
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
.
Solution 3
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.
Solution 4
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.
Solution 5
Also, you can change compilation flags for one file like this:
exe test : test.cpp : <cxxflags>-std=gnu++0x ;
Vicente Botet Escriba
I'm the co-author of the released libraries Boost.Ratio and Boost.Chrono. I'm the author of some other Boost proposals as Boost.Conversion, Boost.Stopwatches. Other libraries that I have not yet proposed to Boost, but that could be proposed soon are Boost.Opaque, Boost.Enums, an extension to Boost.Endian, Boost.Bitfields, Boost.Async, Boost.Synchro, and Boost.Interthreads.
Updated on July 09, 2022Comments
-
Vicente Botet Escriba almost 2 years
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
-
Vicente Botet Escriba about 13 yearsHi, I don't see nothing in this page related to c++0x. Please could you clarify your response?
-
Johan Lundberg almost 11 yearsWith newer versions of boost it is ./b2 toolset=gcc cxxflags=-std=gnu++0x. With newer versions of gcc, use -std=gnu++11
-
Emile Cormier over 9 yearsWith newer versions, you can use
std=c++11
if you don't want to enable the GNU extensions.