peoro peoro - 4 months ago 7x
Linux Question

GLIBCXX versions

If I compile a C++ program on my machine, and run it on another one (with older software) I get:

/usr/lib/ version `GLIBCXX_3.4.9' not found

In fact on my system glibc is newer (I got gcc-libs 4.5.1: and
strings /usr/lib/ | grep GLIBCXX
prints from
. On the other system, instead, it only prints up to
(I got

So I've got a few questions:

  1. Why my linker links C++ binaries against libstdc++ version
    instead of

  2. If I complied my binary against libstdc++ version
    I guess it would run almost on everywhere. Would that imply any sort of issues? (eg: would it use older -and thus worse- algorithm implementations?)

  3. If instead I statically link my program against my libstdc++ I guess it will run everywhere; the binary will be a lot bigger (~1MB) of course, any other pros/cons?

  4. Can I force the linker to link my binary against a given version of libstdc++?


Use readelf -a and objdump -x to inspect ELF files in preference to strings.

Actually, all the GLIBCXX_* versions don't apply to the entire library, but to each symbol (symbol versioning, see DSO-howto). So you can have e.g: std::char_traits<wchar_t>::eq@@GLIBCXX_3.4.5 and std::ios_base::Init::~Init()@@GLIBCXX_3.4 on the same library file.

The fact that your program needs GLIBCXX_3.4.9 probably means that it has been linked against a symbol that has been introduced/has changed semantics on GLIBCXX_3.4.9.