Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++ always backward-compatible with "older" static libraries?

I have a few static libraries, which I'm not the owner of, compiled with an old version of g++ 4.3.2 (c++11/c++0x not activated).

When I compile my code with g++ 4.6 (no c++11) and link it using g++ 4.6 with these static libraries, it links fine and I do not seem to get any issues at runtime (not tested everything though). I'm tempted to think that forward compatibility is OK.

Now I'd like to compile my code with gcc 4.8 with c++11 and still link it with those same, not recompiled static libraries.

Are ABI changes in g++ only an issue for linkage forward compatibility or can one get backward compatibility issues too?

like image 450
Yohan Danvin Avatar asked Apr 24 '13 11:04

Yohan Danvin


People also ask

Is G ++ backwards compatible?

In order to allow compilation of C++ written to such drafts, G++ contains some backwards compatibilities. All such backwards compatibility features are liable to disappear in future versions of G++. They should be considered deprecated.

What is backward compatibility in database?

What is backward compatible (backward compatibility)? Backward compatible (also known as downward compatible or backward compatibility) refers to a hardware or software system that can successfully use interfaces and data from earlier versions of the system or with other systems.

Is Java fully backwards compatible?

Backward CompatibilityJava versions are expected to be binary backwards-compatible. For example, JDK 8 can run code compiled by JDK 7 or JDK 6. It is common to see applications leverage this backwards compatibility by using components built by different Java version.

Is GCC backward compatible?

In general, yes, GCC 4 is backward compatible with GCC 3, even to the point that you can link code compiled with a mix of GCC versions and expect it to just work. There are just a handful of obscure exceptions where the developers were forced to change the C++ ABI, and these are noted in the release notes .


1 Answers

The G++ ABI for C++98 code is backward compatible, all the way back to GCC 3.4

So if you compile and link your final executable with GCC 4.8 you can link to objects and libraries built with anything from GCC 3.4 to 4.8 (but no newer)

The C++11 ABI is the same as the C++98 ABI and the standard library types that are common to both C++98 and C++11 have the same definitions, (ignoring GCC 4.7.0 and GCC 4.7.1, which had ABI incompatibilities in std::pair and std::list when using C++11, which have been fixed in 4.7.2 and later versions) so you can link C++98 and C++11 code together (unless the C++11 code was built with GCC 4.7.0 or 4.7.1)

However some C++11 library types are not stable yet and change between releases, e.g. because they were first shipped before the final C++11 standard and had to be changed to match the final rules. So it's not necessarily safe to mix C++11 code built with GCC 4.6 and C++11 code built with GCC 4.8

For your case, where all the C++11 code is built with GCC 4.8 that will be OK. If you upgrade the compiler you should rebuild all the C++11 code with the newer GCC to be safe. (You don't need to rebuild the C++98/C++03 code)

like image 120
Jonathan Wakely Avatar answered Sep 20 '22 14:09

Jonathan Wakely