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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2887707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:23:32  来源:igfitidea点击:

How to build Boost with C++0x support?

c++boostc++11bjam

提问by Vicente Botet Escriba

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?

我不知道如何使用 C++0x 编译器构建 Boost。必须给 bjam 哪个选项?应该修改 user.config 文件吗?有人可以帮我吗?

Best, Vicente

最好的,维森特

回答by Vicente Botet Escriba

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. For example for gcc we can do

但目前我们需要使用低级变量 cxxflags 并添加特定的编译器标志。例如对于 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

回答by Gabriel

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++11for better compatibility and -std=gnu++11for the gnu extensions (only for gcc)

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

这是来自 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.

安装到/usr/local.

回答by Sean

To compile using clang, use the cxxflagsand linkflags:

要使用 clang 进行编译,请使用cxxflagsand linkflags

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

Passing a -vto cxxflagsis also helpful when debugging.

在调试时传递一个-vtocxxflags也很有帮助。

回答by Pieter

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.

我遇到了一篇使用 clang 编译 Boost 的文章:http: //blog.llvm.org/2010/05/clang-builds-boost.html。有可能将那里提出的用于使用 Boost.Jam 编译 Boost 的更改调整为您最喜欢的 C++0x 编译器。

回答by Bunkar

Also, you can change compilation flags for one filelike this:

此外,您可以像这样更改一个文件的编译标志

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

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