我有一个安装了devtoolset-6的centos 6的对接映像,我想用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文档声明默认是生成新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所以很明显我错过了一些琐碎的东西。
有什么帮助吗?
发布于 2017-07-18 03:18:37
问题在于devtoolset-6中的gcc6编译器没有像Praetorian所建议的那样具有正确的stdlib。
从零开始编译gcc6编译器可以解决这个问题。
https://stackoverflow.com/questions/45155347
复制相似问题