Reputation: 631
I have a docker image for centos 6 with devtoolset-6 installed and I want to build my code with the new ABI available in gcc>=5
, in this case gcc6
. Somehow I do not get what I expect to work by default. I have tried various variations but I am at loss what trivial thing I am missing.
Any suggestion what I am missing would be greatly appreciated...
On compiling the sample code below I expected to see:
$ gcc -c test.cpp –o test.o
$ nm test.o
0000000000000000 T _Z1fNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
0000000000000000 r _ZStL19piecewise_construct
Building the following Dockerfile
generates a centos6 image with gcc6:
FROM centos:6
MAINTAINER [email protected]
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"]
and running the image with
docker run -it centos6_gcc6_test
the following snippet of code does not give the expected results
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
I get the old ABI version, even though the gcc documentation states that the default is to generate the 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 /]#
Even when compiling explicitly with -D_GLIBCXX_USE_CXX11_ABI=1
it still gives the incorrect result:
[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
So obviously I am missing something trivial.
Any help?
Upvotes: 3
Views: 359
Reputation: 631
The problem was that the gcc6 compiler in devtoolset-6 didn't have the right stdlib as Praetorian suggested.
Compiling the gcc6 compiler from scratch solves the problem.
Upvotes: 3