Detect old/new GCC ABI

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,

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).