cmake build_error ai_generated partial

CMake Error: The target 'myapp' links to target 'mylib' which uses GLIBCXX_USE_CXX11_ABI=0, but myapp uses GLIBCXX_USE_CXX11_ABI=1. This is an ABI incompatibility.

ID: cmake/glibcxx-use-cxx11-abi-mismatch

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
1Evidence
2023-05-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.16 active
3.21 active
3.24 active
3.28 active

Root Cause

A project links libraries compiled with different C++ standard library ABI versions (old vs new std::string layout), causing symbol incompatibility at link time.

generic

中文

项目链接了使用不同 C++ 标准库 ABI 版本(旧版与新版 std::string 布局)编译的库,导致链接时符号不兼容。

Official Documentation

https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

Workarounds

  1. 85% success Ensure all dependencies are built with the same ABI setting. Rebuild mylib with -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=1 or rebuild myapp with -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0 to match mylib.
    Ensure all dependencies are built with the same ABI setting. Rebuild mylib with -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=1 or rebuild myapp with -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0 to match mylib.
  2. 80% success Use target_compile_definitions(mylib INTERFACE _GLIBCXX_USE_CXX11_ABI=0) or the equivalent for myapp to propagate the ABI choice consistently.
    Use target_compile_definitions(mylib INTERFACE _GLIBCXX_USE_CXX11_ABI=0) or the equivalent for myapp to propagate the ABI choice consistently.
  3. 75% success If using a package manager like vcpkg or conan, ensure the triplet or profile sets the ABI flag uniformly across all libraries.
    If using a package manager like vcpkg or conan, ensure the triplet or profile sets the ABI flag uniformly across all libraries.

中文步骤

  1. 确保所有依赖项使用相同的 ABI 设置。使用 -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=1 重新编译 mylib,或使用 -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0 重新编译 myapp 以匹配 mylib。
  2. 在 CMakeLists.txt 中使用 target_compile_definitions(mylib INTERFACE _GLIBCXX_USE_CXX11_ABI=0) 或为 myapp 使用相应设置,以一致地传播 ABI 选择。
  3. 如果使用 vcpkg 或 conan 等包管理器,请确保 triplet 或 profile 在所有库中统一设置 ABI 标志。

Dead Ends

Common approaches that don't work:

  1. Adding -D_GLIBCXX_USE_CXX11_ABI=0 to CMAKE_CXX_FLAGS for all targets 70% fail

    This forces the old ABI for all targets, but if system libraries (e.g., Boost) are compiled with the new ABI, the mismatch persists.

  2. Manually editing the generated Makefile to remove conflicting flags 95% fail

    The Makefile is regenerated by CMake on each run, so manual edits are overwritten and not portable across builds.

  3. Setting CMAKE_CXX_STANDARD to a lower value to avoid C++11 ABI 90% fail

    The ABI mismatch is independent of the C++ standard version; it relates to the std::string implementation, not the language standard.