CXX11未定义引用GCC 6.2.0

时间:2016-12-08 12:01:41

标签: c++ c++11 gcc abi gcc5

我们在Scientific Linux机器上手动安装了GCC 6.2.0。 C ++应用程序的编译看起来很好但是我们在链接时获得了很多undefined references到CXX11

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

我们知道double ABI issue,但使用-D_GLIBCXX_USE_CXX11_ABI=0进行编译没有任何区别。我们还有其他选择吗?

更新

CMAKE配置如下:

-- 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

这是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

和链接(实际失败的地方)

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

此外,MPICH 3.2已使用新编译器(gcc 6.2.0)构建

1 个答案:

答案 0 :(得分:0)

我不明白为什么当你用std::__cxx11::list编译时你的对象仍然引用了-D_GLIBCXX_USE_CXX11ABI=0,除非在头文件/源文件中重新定义了宏。你应该确保file.o对象被正确放置到应该包含它的任何存档中(并且任何旧版本肯定都没有了)。随着说:

您可能需要链接gcc 6.2.0附带的libstdc ++库,而不是那个看似与早期编译器对应的库的系统版本。

这可能需要使用-nostdlib,然后手动添加-L/(path)/gcc-6.2.0/lib -lstdc++ -lc或类似内容。

或者,您可以使用系统C ++标头而不是gcc 6.2.0标头进行编译。然后,您还应该能够成功链接到系统libstdc ++库。在这种情况下,您需要-nostdinc++然后-I/usr/include/c++/5(例如)。请注意,在这种情况下,-D_GLIBCXX_USE_CXX11_ABI=0将不起作用且不必要;旧图书馆没有双重ABI。

相关问题