【问题标题】:g++ undefined reference to symbol '__cxa_free_exception@@CXXABI_1.3' when building Point Cloud Libraryg++ 构建点云库时对符号“__cxa_free_exception@@CXXABI_1.3”的未定义引用
【发布时间】:2014-01-09 14:00:49
【问题描述】:

我在构建点云库时遇到了很多问题。我正在运行 Ubuntu,并且有 3 个版本的 GCC 和 Clang(可能是问题所在)。我试图使用与 Ubuntu 捆绑在一起的 g++ 4.6 来构建 PCL,因为它似乎已经获得了我尝试过的最远的编译器。但是我有这个问题:

> Linking CXX executable ../../bin/pcl_convert_pcd_ascii_binary cd /home/oni/Projects/pcl/build/io/tools && /usr/bin/cmake -E cmake_link_script CMakeFiles/pcl_convert_pcd_ascii_binary.dir/link.txt
--verbose=1 /usr/bin/g++   -lstdc++ -pthread -fopenmp  -Wno-deprecated -O2 -g  -lstdc++  -Wl,--as-needed CMakeFiles/pcl_convert_pcd_ascii_binary.dir/convert_pcd_ascii_binary.cpp.o
-o ../../bin/pcl_convert_pcd_ascii_binary -rdynamic -L/usr/local/lib -L/home/oni/Projects/OpenNI/Lib /usr/local/lib/libboost_serialization.so /usr/local/lib/libboost_mpi.so /usr/local/lib/libboost_system.so /usr/local/lib/libboost_filesystem.so /usr/local/lib/libboost_thread.so /usr/local/lib/libboost_date_time.so /usr/local/lib/libboost_iostreams.so -lpthread -lm ../../lib/libpcl_common.so.1.7.1 ../../lib/libpcl_io.so.1.7.1 ../../lib/libpcl_common.so.1.7.1 ../../lib/libpcl_io_ply.so.1.7.1 /usr/local/lib/libboost_serialization.so /usr/local/lib/libboost_mpi.so /usr/local/lib/libboost_system.so /usr/local/lib/libboost_filesystem.so /usr/local/lib/libboost_thread.so /usr/local/lib/libboost_date_time.so /usr/local/lib/libboost_iostreams.so -lm /usr/lib/libvtkWidgets.so.5.8.0 /usr/lib/libvtkHybrid.so.5.8.0 /usr/lib/libvtkParallel.so.5.8.0 /usr/lib/libvtkVolumeRendering.so.5.8.0 /usr/lib/libvtkRendering.so.5.8.0 /usr/lib/libvtkIO.so.5.8.0 /usr/lib/libvtkImaging.so.5.8.0 /usr/lib/libvtkGraphics.so.5.8.0 /usr/lib/libvtkFiltering.so.5.8.0 /usr/lib/libvtkCommon.so.5.8.0 /usr/lib/libvtksys.so.5.8.0 -ldl -lm -lpng -lusb-1.0 -lOpenNI
-Wl,-rpath,/usr/local/lib:/home/oni/Projects/pcl/build/lib:/usr/lib/openmpi/lib:/home/oni/Projects/OpenNI/Lib:
-Wl,-rpath-link,/usr/lib/openmpi/lib  /usr/bin/ld: CMakeFiles/pcl_convert_pcd_ascii_binary.dir/convert_pcd_ascii_binary.cpp.o: undefined reference to symbol '__cxa_free_exception@@CXXABI_1.3' /usr/bin/ld: note: '__cxa_free_exception@@CXXABI_1.3' is defined in DSO /usr/local/lib/libstdc++.so so try adding it to the linker command line /usr/local/lib/libstdc++.so: could not read symbols: Invalid operation collect2: ld returned 1 exit status make[2]: *** [bin/pcl_convert_pcd_ascii_binary] Error 1 make[2]: Leaving directory `/home/oni/Projects/pcl/build' make[1]: *** [io/tools/CMakeFiles/pcl_convert_pcd_ascii_binary.dir/all] Error 2 make[1]: Leaving directory `/home/oni/Projects/pcl/build' make: *** [all] Error 2

来自链接器的无效操作真的很奇怪。我也尝试过的一件事是:

# include <iostream>
int main() {
  std::cout << "Hello, world!\n";
}

接着是:

g++ hello.cpp  /tmp/cc29vkpU.o: In function `main': hello.cpp:(.text+0xa): undefined reference to `std::cout' hello.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /tmp/cc29vkpU.o: In function `__static_initialization_and_destruction_0(int, int)': hello.cpp:(.text+0x3d): undefined reference to `std::ios_base::Init::Init()' hello.cpp:(.text+0x42): undefined reference to `std::ios_base::Init::~Init()' collect2: ld returned 1 exit status

但是,如果我尝试:

g++ hello.cpp -lstdc++

一切都很好。

 g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 

我很困惑,但我确定这与我当前的 g++ 设置和我的 libstdc++ 库有关。我试过 apt-get reinstall 但收效甚微

干杯

【问题讨论】:

  • 你真的需要 -lstdc++ 吗?
  • 我记得 gcc 对命令行中库的顺序非常挑剔(依赖应该遵循依赖)-尝试将 -lstdc++ 推到命令行末尾
  • 我会试试的 - 谢谢!

标签: c++ linker g++ point-cloud-library


【解决方案1】:

我刚刚遇到了同样的症状,同样的解决方案 (-lstdc++) 对我有用。您最近是否从 Ubuntu 12 升级到 14,或升级 gcc 的等效版本?

我似乎和 this blogger 处于同一条船上,刚刚从 Ubuntu 12.04 升级到 14.04。

正如他所写:

Ubuntu 14.04 使用较新版本的 GCC 编译器和库。这里的提示是它抱怨核心 C++ 符号:__cxa_free_exception。建议链接器与标准 C++ 库链接已修复此错误。您可以通过将 -lstdc++ 添加到链接器调用来做到这一点。

【讨论】:

  • 谢谢。对于我的情况,我在 target_link_libraries 中添加了 CMake“lstdc++”。例如 target_link_libraries(foobar -lsomelibrary -lstdc++ )。
  • 这个答案中给出的链接链接到一个钓鱼网站。
  • @FlilyHsu 谢谢! (以前没有 - 似乎发生了一些变化。我现在更新了链接。)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-14
  • 1970-01-01
  • 2012-12-05
  • 2012-04-24
  • 2018-12-28
  • 2021-04-28
  • 2011-07-19
相关资源
最近更新 更多