Shray
Shray

Reputation: 181

glibc error when c++ binary compiled dynamically but not statically

Consider the following: I have a c++ file. I use RHEL6 machine to compile my code. But i want my executable/binary to be able to run on RHEL4 as well. Now I have experienced the following 3 cases-

  1. If I compile a simple c++ file on RHEL6 with gcc version 4.4.7, I cannot execute it on RHEL4 machine. The error is

error while loading shared libraries: requires glibc 2.5 or later dynamic linker

The solution to this is given on gcc: Reduce libc required version. After the fix, I am able to run the binary on RHEL4.

  1. If I compile (on RHEL6 with the same gcc version) with static libraries, I am able to execute it on RHEL4 machine. No need of using -Wl,--hash-style=both as in case 1.

  2. If I compile my project(instead of single file) on RHEL6, then I get the following error when I run the binary on RHEL4 platform.

/lib64/libc.so.6: version `GLIBC_2.7' not found

My question is :

a) Why does no error comes in case of statically linking libraries.

b) What is the difference between the errors produced in case 1 and case 3.

Upvotes: 0

Views: 340

Answers (1)

David G. Pickett
David G. Pickett

Reputation: 384

  1. failed to work for that linker, default library and dynamic linking. 3. Static linking copies code from libraries into your executable, and they work pretty consistently wherever that executable file goes. Dynamic linking can be a bit fussy about having the same libraries and library versions in the dynamic library search path at run time, leaving the code incomplete at run time.

Upvotes: 0

Related Questions