tags:

views:

87

answers:

1

Linux C++ programs build with GCC link against libgcc_s.so.1 and libstdc++.so.6 libraries, each of which contains multiple ABIs: newer versions contain ABIs from previous version plus new ones. GCC ABI policy document says programs build against older runtime should be able to be run with the new runtime. So, theoretically, older binaries should be runnable on new systems.

If I have a system with an older runtime and don't want to go through the trouble of upgrading GCC on this system, can I manually replace the above mentioned libraries with new ones? In theory all old executables that link against it should work (including GCC itself), but it feels like a kludge.

Is it safe to do so?

+3  A: 

Maybe, but I don't recommend it, at least not without extensive testing that would almost certainly eat up any gain. Here's why:

  • "ABI compatible" is not necessarily "bug compatible". Even if ABI compatibility is maintained, your apps might still break in surprising ways if they somehow depended on behavior that was incorrect in a previous version of the library.
  • There might be new bugs that end up breaking your apps, again without being ABI-incompatible.
  • If you don't compile the new libraries exactly right, they might not be ABI compatible.
  • Are you sure the original libraries were compiled from pristine GNU sources? Maybe there were patches you don't know about. If you can't be sure of that, you can't be sure of compatibility of your existing system/apps.

What's your goal here? If you just want to be able to compile C++ apps that use newer features, you can install a new version of GCC alongside the original, you just need to make sure all the libraries you might be using are built with the new version, too.

Nicholas Knight
What I'd like to build with GCC 4.5 and deploy on a system that only has libstdc++ from GCC 4.1 or 4.2. But barring a parallel install of a new GCC version it looks less and less like a good idea.
Alex B
@Alex: If it comes down to it, I'd statically link. The binary might be huge (relatively speaking), but for a one-off thing, I wouldn't worry about it, and you'd save all the headache of worrying about library versions. Just drop the static binary on the old system and go.
Nicholas Knight