【发布时间】:2016-12-08 12:01:40
【问题描述】:
我们已经在一台 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) 构建
【问题讨论】:
-
如何链接你的程序?与
ld?与gcc?与g++? -
删除目标文件并重新编译。
-
在安装 gcc 时,gcc 更愿意假设它的库将安装到 /usr/lib(64)? 中,而不管您实际将 gcc 推到哪里。因此,您的代码最终会与系统的标准库链接。不幸的是,我忘记了如何从 gcc 的配置中剔除垃圾的血腥细节,以便正确设置它以与安装它们的库链接。你必须弄清楚,就像我 10 年前所做的那样......如果我记得所有这些,我会发布一个答案。
-
这意味着
file.cpp没有与-D_GLIBCXX_USE_CXX11_ABI=0一起编译。发布编译系统发出的编译器和链接器命令行。 -
@n.m. ——这正是我的意思。期望当我在某个目录中安装 GCC 和 libstdc++ 时,我只是正常链接我的代码,一切都在没有神秘链接选项的情况下工作,这并非不合理。 Freebsd 正确打包了 GCC,多个 gccNN 命令,每个命令都与它的 libstdc++ 链接,并为运行时提供 rpath。