简体   繁体   English

如何使用C ++ 0x支持构建Boost?

[英]How to build Boost with C++0x support?

I don't know how to build Boost with C++0x compilers. 我不知道如何使用C ++ 0x编译器构建Boost。 Which option must be given to bjam? 必须给bjam哪个选项? Should the user.config file be modified?Can someone help me? 是否应修改user.config文件?有人可以帮助我吗?

Best, Vicente 最好的,维森特

I have found the answer. 我找到了答案。 I was waiting for a features something like 'std' and call it as follows: 我正在等待'std'这样的功能,并按如下方式调用:

bjam std=0x

but currently we need to use the low level variables cxxflags and add the specific compiler flags. 但是目前我们需要使用低级变量cxxflags并添加特定的编译器标志。 For example for gcc we can do 例如对于gcc,我们可以做到

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 等待新的Boost.Build功能,您还可以按如下方式定义自己的工具集:添加user.config或site.config文件

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

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) -j12用于并行(12个线程)构建使用-std=c++11以获得更好的兼容性, -std=gnu++11用于gnu扩展(仅适用于gcc)

if boost::mpi is not build (see the output of above command) -> edit the user-config.jam 如果boost :: mpi没有构建(参见上面命令的输出) - >编辑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 ): 这是来自travis的框架的改编脚本(调整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 . 安装在/usr/local

To compile using clang, use the cxxflags and linkflags : 要使用clang进行编译,请使用cxxflagslinkflags

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

Passing a -v to cxxflags is also helpful when debugging. 调试时,将-v传递给cxxflagscxxflags用。

I came across an article for compiling Boost using clang: http://blog.llvm.org/2010/05/clang-builds-boost.html . 我发现了一篇使用clang编译Boost的文章: 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. 有可能调整那里提出的更改,以便使用Boost.Jam将Boost编译为您最喜欢的C ++ 0x编译器。

此外,您可以更改一个文件的编译标志,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM