# Detect old/new GCC ABI

**URL:** https://discourse.cmake.org/t/detect-old-new-gcc-abi/2431
**Category:** Usage
**Created:** [December 28, 2020, 8:58am UTC](https://discourse.cmake.org/t/detect-old-new-gcc-abi/2431 "2020-12-28T08:58:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mmoelle1](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mmoelle1/32/382_2.png) [@mmoelle1](https://discourse.cmake.org/u/mmoelle1)
#### Post date: [December 28, 2020, 8:58am UTC](https://discourse.cmake.org/t/detect-old-new-gcc-abi/2431/1 "2020-12-28T08:58:50Z")

</div>

Dear all,

Is there an approved way to detect if the compiler uses the pre-cxx11 ABI or the cxx11 ABI? In one of my projects I let CMake download libtorch and link my c++ code to it. To the best of my knowledge checking the compiler version is not sufficient since also the GLIBCXX library has to be compiled in either of the two variants. I tried to compile a small test code (with `try_compile`) and check for the presence of `_GLIBCXX_USE_CXX11_ABI` and its value set to 1 but that is insufficient.

Thanks and best regards,  
Matthias

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 28, 2020, 4:15pm UTC](https://discourse.cmake.org/t/detect-old-new-gcc-abi/2431/2 "2020-12-28T16:15:02Z")

</div>

The stdlib itself contains both. The flag only switches which one is in use when the compiler reads `std::string`. That does need to be agreed upon between libtorch headers and your build; the stdlib on its own cannot tell you which was used for it.

I don’t know of a way to detect which is used other than a `try_compile` using libtorch headers and some API which contains `std::string` (or another type with a different C++11 ABI) and detect the linker error about a missing symbol. Note that the `std::string` must be in a place that affects symbol mangling (namely a direct argument; not as a member of a struct being passed).
