使用已安装的 C++11 编译器在 CentOS7 中构建 Boost 1.75 问题

问题描述

我正在尝试在 CentOS7 中构建 boost 1.75。

gccC++ 分别使用以下 shell 脚本更新到版本 9.3.1 和 c++14。

script_update_gcc.sh

sudo yum -y install centos-release-scl
sudo yum -y install devtoolset-9-gcc*
source scl_source enable devtoolset-9
gcc --version
# gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)

script_update_c++.sh

sudo yum -y install centos-release-scl-rh
sudo yum-config-manager --enable centos-release-scl-rh
sudo yum -y install devtoolset-9
source scl_source enable devtoolset-9

我用来从源代码构建 boost 的脚本如下。

wget https://dl.bintray.com/boostorg/release/1.75.0/source/boost_1_75_0.tar.gz
tar -xzf boost_1_75_*
cd boost_1_75_*
sudo ./bootstrap.sh --prefix=/opt/boost 
sudo ./b2 install --prefix=/opt/boost --with=all

但是,我收到以下错误消息

A C++11 capable compiler is required for building the B2 engine.
Toolset 'cxx' does not appear to support C++11.

** Note,the C++11 capable compiler is _only_ required for building the B2
** engine. The B2 build system allows for using any C++ level and any other
** supported language and resource in your projects.


You can specify the toolset as the argument,i.e.:
    ./build.sh gcc

Toolsets supported by this script are:
    acc,clang,como,gcc,intel-darwin,intel-linux,kcc,kylix,mipspro,pathscale,pgi,qcc,sun,sunpro,tru64cxx,vacpp

我试过 ./build.sh gcc文件没有在源文件夹中存在。我还尝试将 gcc 版本添加到 boostrap 中,但也不起作用。

sudo ./bootstrap.sh --prefix=/opt/boost --with-toolset=gcc-9.3.1

作为我最后的手段,我尝试了 clang 但它也没有帮助,并给了我与上面完全相同的错误

./bootstrap.sh toolset=clang cxxflags="-stdlib=libc++ -std=c++11" linkflags="-stdlib=libc++"

有人可以帮助我吗?我已经将 c++gcc 更新到最新版本,但我不知道为什么 boost 抱怨没有支持 c++11 的编译器。

解决方法

您额外的“script_update_c++.sh”将 gcc 4.8 安装到 /usr/bin。我认为这可能会造成干扰。

试试

hash -r
which gcc
gcc --version

(还有 which g++)以找出您的路径所拾取的内容。

如果它报告 GCC 4.8,那么您很可能只是在子 shell 中执行脚本,而不是采购它们。这是行不通的,因为

source scl_source enable devtoolset-9

当前 shell 设置环境变量。因此,要么自行发布,要么通过获取脚本来运行脚本。