c++ - Centos6 gcc6 : default ABI not picked up when compiling simple c++11 test file

标签 c++ c++11 gcc abi gcc6

我有一个安装了 devtoolset-6 的 centos 6 docker 镜像,我想使用 gcc>=5 中可用的新 ABI 构建我的代码,在本例中为 gcc6。不知何故,我没有得到我期望默认工作的东西。我尝试了各种变体,但我不知道我错过了什么微不足道的事情。

任何我遗漏的建议都将不胜感激...

在编译下面的示例代码时,我希望看到:

$ gcc -c test.cpp –o test.o
$ nm test.o
0000000000000000 T _Z1fNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
0000000000000000 r _ZStL19piecewise_construct

构建以下 Dockerfile 生成带有 gcc6 的 centos6 镜像:

FROM        centos:6
MAINTAINER  aap.noot@gmail.com

RUN yum -y update \
    && yum clean all \
    && yum -y install make \
    && yum clean all

RUN yum -y install centos-release-scl \
    && yum -y install devtoolset-6-gcc devtoolset-6-binutils devtoolset-6-gcc-c++ \
    && yum clean all \
    && echo 'source /opt/rh/devtoolset-6/enable' >> ~/.bashrc

RUN /usr/bin/scl enable devtoolset-6 true
ENTRYPOINT ["/usr/bin/scl", "enable", "devtoolset-6", "--"]
CMD ["/usr/bin/scl", "enable", "devtoolset-6", "--", "/bin/bash"]

并运行图像

docker run -it centos6_gcc6_test

下面的代码片段没有给出预期的结果

g++ --version
echo '#include <string>' > test.cpp
echo 'void f(std::string s) {}' >> test.cpp
cat test.cpp
g++ -c -o test.o test.cpp
nm test.o | c++filt

我得到的是旧的 ABI 版本,尽管 gcc 文档指出默认是生成 new ABI

[root@3b58135d30a2 /]# g++ --version
g++ (GCC) 6.2.1 20160916 (Red Hat 6.2.1-3)
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@3b58135d30a2 /]# echo '#include <string>' > test.cpp
[root@3b58135d30a2 /]# echo 'void f(std::string s) {}' >> test.cpp
[root@3b58135d30a2 /]# cat test.cpp
#include <string>
void f(std::string s) {}
[root@3b58135d30a2 /]# g++ -c -o test.o test.cpp
[root@3b58135d30a2 /]# nm test.o | c++filt
0000000000000000 T f(std::basic_string<char, std::char_traits<char>,   std::allocator<char> >)
0000000000000000 r std::piecewise_construct
[root@3b58135d30a2 /]#

即使使用 -D_GLIBCXX_USE_CXX11_ABI=1 显式编译,它仍然会给出不正确的结果:

[root@3b58135d30a2 /]# g++ -D_GLIBCXX_USE_CXX11_ABI=1 -c -o test.o test.cpp
[root@3b58135d30a2 /]# nm test.o | c++filt
0000000000000000 T f(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)
0000000000000000 r std::piecewise_construct

很明显我遗漏了一些微不足道的东西。

有什么帮助吗?

最佳答案

问题是 devtoolset-6 中的 gcc6 编译器没有 Praetorian 建议的正确标准库。

从头开始编译 gcc6 编译器解决了这个问题。

关于c++ - Centos6 gcc6 : default ABI not picked up when compiling simple c++11 test file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45155347/

相关文章:

c++ - Dev C++简单线程程序

c - 在 64 位 Windows 7 机器上使用 GCC 作为 MATLAB 2014a 的默认 MEX 编译器

c - 堆栈分配、填充和对齐

无法将 UNIX/Linux 程序编译为 32 位程序

c++ - 这是 Solaris Studio 中的一个错误吗?

c++ - unsigned short 和 signed short 比较奇怪的行为

c++ - Directx11 项目不会显示图形输出

c++ - 可变参数模板中的类成员函数

c++ - "Overloading"带有 SFINAE 的构造函数

c++ - 我可以使用std::array的自定义分配器来获得安全的加密 key 吗?