_GLIBCXX_USE_CXX11_ABI, compatible with GCC 4.8 and ABI

We got some libraries (.a) compiled for linux (possibly compiled using GCC 6.x).

We use GCC 4.8, and we get an error like: undefined reference to std::__cxx11::basic_string when trying to link.

This can usually be fixed by making sure that all units have been compiled with the same _GLIBCXX_USE_CXX11_ABI flag. However, if I understood correctly, this was introduced by GCC 5.1 onward.

  • Is there a way to make this work with GCC 4.8 or do we need to ask people to recompile the libraries using another _GLIBCXX_USE_CXX11_ABI ?
  • I think if we can switch to GCC> = 5.1, can we do this work?

Thanks!

+8
c ++ gcc linux c ++ 11
source share
1 answer

You can use C ++ 11 ABI with gcc 4.8.2, but this is a dangerous hack; you would be much better off if you could ask your vendors to send libraries compiled with C ++ 03 ABI ( -D_GLIBCXX_USE_CXX11_ABI=0 ), or to upgrade to GCC 5 or higher.

You will need to download and install gcc 5 so that you can use its libstdc ++ headers and libraries, and then use gcc 4.8 directly, which is preferable. In addition, since gcc 4.8 lacks some of the properties required by libstdc ++ that ship with gcc 5, you will need to wrest their usage.

For example, to compile a simple single-file application that includes <string> :

 /usr/local/gcc-4.8.2/bin/g++ \ -std=c++11 \ -D_GLIBCXX_USE_CXX11_ABI=1 \ -D'__is_trivially_copyable(...)=0' \ -D'__is_trivially_constructible(...)=0' \ -D'__is_trivially_assignable(...)=0' \ -nostdinc++ \ -isystem /usr/local/gcc-5.4.0/include/c++/5.4.0/ \ -isystem /usr/local/gcc-5.4.0/include/c++/5.4.0/x86_64-unknown-linux-gnu \ -L /usr/local/gcc-5.4.0/lib64 a.cpp 

This is dangerous because gcc 5.4 libstdC ++ is not designed to work with gcc 4.8, and overriding the built-in tools used ( __is_trivially_copyable , etc.) can change the layout of structures or otherwise cause binary incompatibility between your programs and provider libraries.

To run the resulting executable, you also need to make sure that the dynamic linker finds compatible libstdc ++, for example by adding /usr/local/gcc-5.4.0/lib64 to /etc/ld.so.conf or using -Wl,-rpath /usr/local/gcc-5.4.0/lib64 .

+4
source share

All Articles