[ACCEPTED]-gcc: Reduce libc required version-libc

Accepted answer
Score: 26

An untested possible solution

What is "error while loading shared libraries: requires glibc 2.5 or later dynamic linker"?

The cause of 18 this error is the dynamic binary (or one 17 of its dependent shared libraries) you 16 want to run only has .gnu.hash section, but 15 the ld.so on the target machine is too 14 old to recognize .gnu.hash; it only recognizes 13 the old-school .hash section.

This usually 12 happens when the dynamic binary in question 11 is built using newer version of GCC. The 10 solution is to recompile the code with either 9 -static compiler command-line option (to 8 create a static binary), or the following 7 option:

-Wl,--hash-style=both

This tells the link editor ld to 6 create both .gnu.hash and .hash sections.

According 5 to ld documentation here, the old-school .hash section is the 4 default, but the compiler can override it. For 3 example, the GCC (which is version 4.1.2) on 2 RHEL (Red Hat Enterprise Linux) Server release 1 5.5 has this line:

$ gcc -dumpspecs
....
*link:
%{!static:--eh-frame-hdr} %{!m32:-m elf_x86_64} %{m32:-m elf_i386} --hash-style=gnu   %{shared:-shared}   ....
                                                                   ^^^^^^^^^^^^^^^^
...

For more information, see here.

Score: 5

I already had the same problem, trying to 12 compile a little tool (I wrote) for an old 11 machine for which I had not compiler. I 10 compiled it on an up to date machine, and 9 the binary required at least GLIBC 2.14 8 in order to run.

By making a dump of the 7 binary (with xxd), I found this :

....
5f64 736f 5f68 616e 646c 6500 6d65 6d63  _dso_handle.memc
7079 4040 474c 4942 435f 322e 3134 005f  py@@GLIBC_2.14._
....

So I replaced 6 the memcpy calls in my code by a call to 5 an home-made memcpy, and the dependency 4 with the glibc 2.14 magically disappeared.

I'm 3 sorry I can't really explain why it worked, or 2 I can't explain why it didn't work before 1 the modification.

Hope it helped !

Score: 3

Ok then, trying to find some balance between 4 elegance and brute force, I downloaded a 3 VM matching the target kernel version, hence fixing library issues.
The 2 whole thing (download + yum install gcc) took 1 less than 30 minutes.

References: Virtual machines, Kernel Version Mapping Table

More Related questions