I have a configuration probe that determines what flags to pass to g++ based on platform and version. I typically use a later version of gcc than the native install version in order to gain access to C++14 features.
On older platforms this means I need to add -D_GLIBCXX_USE_CXX11_ABI=0 to use the older C++ ABI or I cannot link with host versions of C++ libraries.
However some newer platforms do use the new ABI in which case -D_GLIBCXX_USE_CXX11_ABI=1 (or nothing at all) is required.
I can do this based on the version of the target platform (i.e. the output of lsb_release -a) but I would like a more general method.
I think I'm half way there with compiling a C++ hello world program with the native compiler (as opposed to my later one) but I can't quite figure out how to probe the ABI version.
>strings hello | grep ABI
>strings hello | grep CXX
ldd ./hello | grep stdc++ | sed -e 's_.* /_/_' | cut -f 1 -d' ' |xargs strings | grep
Contrary to popular belief minor versions of libstdc++ aren't always binary compatible.
They aren't binary compatible in both directions. libstdc++.so.6.0.20 can be used when libstdc++.so.6.0.19 is required, but not the other way round.
However, prior to GCC 5 the C++11 support was still experimental (i.e. work in progress) and so the ABI of new C++11 components was not stable, so you can't mix C++11/C++14 code compiled with GCC 4.x and GCC 4.y, or GCC 4 and GCC 5. For C++98 code you can mix&match freely (just use the newer
libstdc++.so because it's only compatible in one direction).
The details of the major C++11 incompatibilities prior to GCC 5 are documented at https://gcc.gnu.org/wiki/Cxx11AbiCompatibility
Anyway, to answer the now irrelevant question:
I think I'm half way there with compiling a C++ hello world program with the native compiler (as opposed to my later one) but I can't quite figure out how to probe the ABI version
If you can run the native compiler then I don't see what the problem is, just check the default value of the macro:
echo '#include <string>' | g++ -x c++ -E -dM - | fgrep _GLIBCXX_USE_CXX11_ABI