It's possible to use the C++11 ABI with gcc 4.8.2, but it's a dangerous hack; you would be far better off if at all possible to ask your vendors to ship libraries compiled with the C++03 ABI (-D_GLIBCXX_USE_CXX11_ABI=0
) or to upgrade to GCC 5 or above.
You would need to download and install gcc 5 so that you can use its libstdc++ headers and libraries, then direct gcc 4.8 to use those in preference to its own. In addition, because gcc 4.8 is missing some intrinsics required by the libstdc++ shipped with gcc 5, you would need to hack out 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 the gcc 5.4 libstdc++ is not designed to work with gcc 4.8, and redefining the intrinsics used (__is_trivially_copyable
etc.) could change the layout of structures or otherwise cause binary incompatibility between your programs and the vendor's libraries.
In order to run the resulting executable, you would also need to ensure that the dynamic linker finds a 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
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…