c++c++11gccabigcc5

CXX11 undefined references with GCC 6.2.0


We have manually installed GCC 6.2.0 on a Scientific Linux machine. The compilation of a C++ application seems fine but we get lots of undefined references to CXX11 at linking time

file.cpp:(.text+0x16cb): undefined reference to `std::__cxx11::list<void*, std::allocator<void*> >::list(std::__cxx11::list<void*, std::allocator<void*> > const&)'

We are aware of the double ABI issue but compiling with -D_GLIBCXX_USE_CXX11_ABI=0 makes no difference. What other options do we have?

UPDATE

The CMAKE configuration is as follow:

-- The C compiler identification is GNU 6.2.0
-- The CXX compiler identification is GNU 6.2.0
-- Check for working C compiler: /opt/GNU/gcc-6.2.0/bin/gcc
-- Check for working C compiler: /opt/GNU/gcc-6.2.0/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /opt/GNU/gcc-6.2.0/bin/g++
-- Check for working CXX compiler: /opt/GNU/gcc-6.2.0/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done

This is the compilation line of file.cpp

gcc-6.2.0/bin/g++ -O3 -fopenmp -DNO_HDF5 -D_GLIBCXX_USE_CXX11_ABI=0  -I./include -I/opt/mpich/3.2/include  -o file.cpp.o -c file.cpp

and linking (where it actually fails)

gcc-6.2.0/bin/g++ -O3 -fopenmp -DNO_HDF5 -D_GLIBCXX_USE_CXX11_ABI=0     main.cpp.o  -o ASTEP -rdynamic libMainASTEPlib.a -lhdf5_hl -lhdf5 -lz -lm -lhdf5_hl -lhdf5 -lz -lm /opt/mpich/3.2/lib/libmpicxx.so /opt/mpich/3.2/lib/libmpi.so -Wl,-rpath,/opt/mpich/3.2/lib

Also, MPICH 3.2 has been built with the new compiler (gcc 6.2.0)


Solution

  • I don't understand why your object still has references to std::__cxx11::list when you have compiled with -D_GLIBCXX_USE_CXX11ABI=0, unless the macro is then being redefined in a header/source file. You should make certain the file.o object is correctly being placed into whatever archive is supposed to contain it (and that any old version is definitely gone). With that said:

    You may need to link against the libstdc++ library that comes with gcc 6.2.0, not with the system version of that library which seemingly corresponds to an earlier compiler.

    This may require using -nostdlib and then manually adding -L/(path)/gcc-6.2.0/lib -lstdc++ -lc or similar.

    Alternatively, you may be able to compile using the system C++ headers rather than the gcc 6.2.0 headers. Then you should also be able to successfully link against the system libstdc++ library. In that case you want -nostdinc++ and then -I/usr/include/c++/5 (for example). Note that in this case, -D_GLIBCXX_USE_CXX11_ABI=0 will have no effect and is unnecessary; the old library does not have the dual ABI.