使用abi:cxx11的GCC未定义引用 [英] GCC undefined references with abi:cxx11

查看:1944
本文介绍了使用abi:cxx11的GCC未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gcc 5.4.0 20160609(Ubuntu 5.4.0-6ubuntu1〜16.04.11)编译C ++程序。

I'm compiling C++ programs with gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11). Everything is fine at compile time.

然后将这些程序链接到使用 gcc版本4.8.4构建的库(Ubuntu 4.8.4) -2ubuntu1〜14.04.3)

I then link those programs with a library that was built with gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3).

然后我得到未定义的引用链接错误:

I then get undefined reference link errors:

CMakeFiles/FOSSSim.dir/RigidBodies/RigidBodyGRVelocityProjectionCollisionResolver.cpp.o:(.rodata._ZTV46RigidBodyGRVelocityProjectionCollisionResolver[_ZTV46RigidBodyGRVelocityProjectionCollisionResolver]+0x18): undefined reference to `RigidBodyGRVelocityProjectionCollisionResolver::getName[abi:cxx11]() const'
CMakeFiles/FOSSSim.dir/RigidBodies/RigidBodyGRLCPCollisionResolver.cpp.o:(.rodata._ZTV31RigidBodyGRLCPCollisionResolver[_ZTV31RigidBodyGRLCPCollisionResolver]+0x18): undefined reference to `RigidBodyGRLCPCollisionResolver::getName[abi:cxx11]() const'
CMakeFiles/FOSSSim.dir/RigidBodies/RigidBodyVelocityProjectionCollisionResolver.cpp.o:(.rodata._ZTV44RigidBodyVelocityProjectionCollisionResolver[_ZTV44RigidBodyVelocityProjectionCollisionResolver]+0x18): undefined reference to `RigidBodyVelocityProjectionCollisionResolver::getName[abi:cxx11]() const'
CMakeFiles/FOSSSim.dir/RigidBodies/RigidBodyLCPCollisionResolver.cpp.o:(.rodata._ZTV29RigidBodyLCPCollisionResolver[_ZTV29RigidBodyLCPCollisionResolver]+0x18): undefined reference to `RigidBodyLCPCollisionResolver::getName[abi:cxx11]() const'
CMakeFiles/FOSSSim.dir/RigidBodies/RigidBodyAllPairsCollisionDetector.cpp.o:(.rodata._ZTV34RigidBodyAllPairsCollisionDetector[_ZTV34RigidBodyAllPairsCollisionDetector]+0x18): undefined reference to `RigidBodyAllPairsCollisionDetector::getName[abi:cxx11]() const'

的一些引用,我发现了一些链接,例如 linking-problems-due-to-symbols-with-abicxx11 处理 -D_GLIBCXX_USE_CXX11_ABI = 0 编译选项。不幸的是,当我使用该选项时,会收到Cmake警告:

With some googling, I found some links like linking-problems-due-to-symbols-with-abicxx11 dealing with the -D_GLIBCXX_USE_CXX11_ABI=0 compiling option. Unfortunately, when I use that option, I get a Cmake warning:

CMake Warning:
  Manually-specified variables were not used by the project:

    _GLIBCXX_USE_CXX11_ABI

任何线索解决问题的方法?知道我更愿意避免更改编译器版本。

谢谢。

推荐答案

_GLIBCXX_USE_CXX11_ABI 是预处理器宏,用于控制GNU C ++标准库实现的行为。它需要传递给预处理器,而不是CMake。

_GLIBCXX_USE_CXX11_ABI is a preprocessor macro that controls the behavior of the GNU C++ standard library implementation. It needs to be passed to the preprocessor, not CMake.

在您的计算机中使用 add_compile_definitions(-D_GLIBCXX_USE_CXX11_ABI = 0) CMakeLists.txt或在命令行上通过CMAKE_CXX_FLAGS传递:

Use add_compile_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) in your CMakeLists.txt or pass it via CMAKE_CXX_FLAGS on the command line:

cmake -DCMAKE_CXX_FLAGS='-D_GLIBCXX_USE_CXX11_ABI=0' path/to/your/project

请注意,尽管这可能会使您的程序得以构建,但可能不会足以使一切正常。混合由不同版本的GCC编译的目标代码充满了问题。

Note that while this may get your program to build, it likely won't be enough to make everything work. Mixing object code compiled by different versions of GCC is fraught with issues.

这篇关于使用abi:cxx11的GCC未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆