How to explore the C ++ ABI used by the gcc system version on the target platform

I have a configuration probe that determines which flags are passed to g ++ based on the platform and version. I usually use a later version of gcc than the native version to install to access the 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 I can not associate with the versions of the C ++ library hosts. However, some new platforms use the new ABI, in this 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. lsb_release -a output), but I need a more general method.

I think I'm halfway with compiling the C ++ global welcome program with a native compiler (unlike my later one), but I can't figure out how to research the ABI version. For instance.

  > strings hello |  grep ABI
 .note.ABI-tag
 > strings hello |  grep CXX
 GLIBCXX_3.4

or similarly in the version of libstdC ++ used by hello probe.

  ldd ./hello |  grep stdc ++ |  sed -e 's _. * / _ / _' |  cut -f 1 -d '' | xargs strings |  grep 

Does anyone have any better suggestions?

update: Actually, I don’t need to do this at all. My real problem was that I had an older version of libstdc ++. The compilation took one of the versions 6.0.20, and the runtime took the incompatible value 6.0.19 (or, conversely, vice versa). I had an unresolved character that I incorrectly blamed on the ABI version. Contrary to popular belief, minor versions of libstdC ++ are not always binary compatible. My intention is to always use the same version at startup and compile time (if you do not use the main server).

+5
source share
1 answer

Contrary to popular belief, minor versions of libstdc ++ are not always binary compatible.

They are not binary, compatible in both directions. libstdc ++. so.6.0.20 can be used when libstdc ++. so.6.0.19 is required, but not vice versa.

However, prior to GCC 5, C ++ 11 support was still experimental (i.e., work in progress), and therefore the ABI of the new C ++ 11 components was not stable, so you cannot mix C ++ 11 / C ++ code 14, compiled with GCC 4.x and GCC 4.y, or GCC 4 and GCC 5. For C ++ 98 code, you can easily mix and match freely (just use the newer libstdc++.so , because it is compatible with only one direction).

Details of major C ++ 11 incompatibilities prior to GCC 5 are documented at https://gcc.gnu.org/wiki/Cxx11AbiCompatibility

In any case, to answer the now irrelevant question:

I think I'm halfway with compiling a global C ++ welcome program with a native compiler (unlike my later one), but I can't figure out how to research the ABI version

If you can run your own compiler, then I don’t understand 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 
0
source

Source: https://habr.com/ru/post/1240519/


All Articles