我正在用gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11)
编译C ++程序。编译时一切都很好。
然后我将这些程序链接到使用gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
构建的库。
然后我得到未定义的参考链接错误:
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'
通过一些谷歌搜索,我发现诸如{{3}}之类的链接正在处理-D_GLIBCXX_USE_CXX11_ABI=0
编译选项。不幸的是,当我使用该选项时,会收到Cmake警告:
CMake Warning:
Manually-specified variables were not used by the project:
_GLIBCXX_USE_CXX11_ABI
是否有解决问题的线索?知道我宁愿避免更改编译器版本。
谢谢。
答案 0 :(得分:1)
_GLIBCXX_USE_CXX11_ABI
是一个预处理器宏,用于控制GNU C ++标准库实现的行为。它需要传递给预处理器,而不是CMake。
在您的CMakeLists.txt中使用add_compile_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
或在命令行上通过CMAKE_CXX_FLAGS传递它:
cmake -DCMAKE_CXX_FLAGS='-D_GLIBCXX_USE_CXX11_ABI=0' path/to/your/project
请注意,虽然这可以使您的程序得以构建,但可能不足以使一切正常运行。混合由不同版本的GCC编译的目标代码充满了问题。