3

我们已经在一台 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&)'

我们知道双重 ABI 问题,但编译-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) 构建

4

1 回答 1

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。

于 2016-12-08T14:11:14.050 回答