我的生产环境是 Centos 7,仅限于:
在那个环境下,无论我使用 gcc 4.8.5 还是 gcc 7.3.1 (devtoolset-7),它仍然使用旧的 ABI libstdc++。
我的开发环境是一个 Centos 8 Stream,带有新的 libstdc++11 和 gcc 8.4.1:
当然,运行我在 Centos 8 Stream 上编译的应用程序,在 Centos 7 上,我得到了著名的:
从 Centos 8 Stream,我如何告诉 CMake 使用 旧的 ABI 以便它与 Centos 7 兼容?
柯南有一个 compiler.libcxx=libstdc++
选项。
我确实有 set(CMAKE_CXX_STANDARD 11)
,两个 gcc 版本都支持 C++11。
cmake -D_GLIBCXX_USE_CXX11_ABI=0 ..
CMake Warning:
Manually-specified variables were not used by the project:
_GLIBCXX_USE_CXX11_ABI
-DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0
/usr/bin/ld: Dwarf Error: Invalid abstract instance DIE ref.
/tmp/ccXH3FbV.ltrans0.ltrans.o: In function `main':
<artificial>:(.text+0xbb5): undefined reference to `MyLib::getStateString[abi:cxx11]()'
<artificial>:(.text+0xbe0): undefined reference to `MyLib::getState2String[abi:cxx11]()'
<artificial>:(.text+0xeb8): undefined reference to `MyLib::MyLib(unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'