1

I have a binary which build for an older version linux, and when I put the binary in a newer linux and try to run it, it tells "no such file or directory" error.

I searched and found this is about improper library linking. I used ldd on this binary and the output shown is like this:

./test.exe: /lib/libpthread.so.0: version 'GLIBC_2.1' not found (required by ./test.exe) ./test.exe: /lib/libpthread.so.0: version 'GLIBC_2.0' not found (required by ./test.exe) ./test.exe: /lib/libpthread.so.0: version 'GLIBC_2.3.2' not found (required by ./test.exe) ./test.exe: /lib/libc.so.6: version 'GLIBC_2.1.3' not found (required by ./test.exe) ./test.exe: /lib/libc.so.6: version 'GLIBC_2.1' not found (required by ./test.exe) ./test.exe: /lib/libc.so.6: version 'GLIBC_2.0' not found (required by ./test.exe) libpthread.so.0 => /lib/libpthread.so.0 (0x40004000) libstdc++.so.5 => not found libm.so.6 => /lib/libm.so.6 (0x40025000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x400cd000) libc.so.6 => /lib/libc.so.6 (0x400e1000) /lib/ld-linux.so.2 => /lib/ld-linux.so.3 (0x2a000000) I did tried to compile the binary with -static to try to embedded required library into the binary (if I understand the -static option correct), but result did not change. I am unfamiliar with the compile-link things. Could anyone provide some help on how to solve this problem? Thank you!

All I want to do is to make this binary run on the newer version linux, I also searched few solutions which suggests to copy older library to some folder and use a "wrapper" to force this binary to use the library in that folder, but still get no lucky.

UPDATE:

I am doing it for ARM linux. I did not mention it because I did not realize it matters.

The two linux versions, however, come from the same company which they name as ts-linux. We purchased ARM board from them and they also provide several linux versions for customers to use.

Based on this fact, I think the two linux should not be that different as GLIBC and uClibc. I tried to copy the old library to new system and set LD_LIBRARY_PATH to the old library, but then all system commands donot function, for example,

ts7800-16:~# export LD_LIBRARY_PATH=/root/libtemp/ ts7800-16:~# ls ls: /root/libtemp/libgcc_s.so.1: version 'GCC_3.5' not found (required by ls) ls: /root/libtemp/libc.so.6: version 'GLIBC_2.4' not found (required by ls) ls: /root/libtemp/libc.so.6: version 'GLIBC_2.4' not found (required by /lib/libselinux.so.1) ls: /root/libtemp/libc.so.6: version 'GLIBC_2.4' not found (required by /lib/librt.so.1) ls: /root/libtemp/libpthread.so.0: version 'GLIBC_2.4' not found (required by /lib/librt.so.1) ls: /root/libtemp/libc.so.6: version 'GLIBC_2.4' not found (required by /lib/libacl.so.1) ls: /root/libtemp/libc.so.6: version 'GLIBC_2.4' not found (required by /lib/libdl.so.2) ls: /root/libtemp/libc.so.6: version 'GLIBC_2.4' not found (required by /lib/libattr.so.1)

It seems to me they are also using some other version of GLIBC (forgive my ignorance if I am wrong)

I did checked linux version, and following is the two:

ts7800-16:~# more /etc/debian_version

6.0.3

root@ts7800:root# more /etc/debian_version

3.1 Sarge

SamTest
  • 299
  • 3
  • 13

2 Answers2

2

How to run a binary which require an older glibc library in an newer Linux?

GLIBC maintains backward compatibility -- older binaries continue to work on newer systems. That means that usually you don't need to do anything -- your older binary just runs.

 /lib/ld-linux.so.2 => /lib/ld-linux.so.3 (0x2a000000)

That line is very strange (note 2 vs. 3 external version). It suggests that you are in fact using something other than GLIBC on your system (which would also explain why it is missing all the GLIBC* version labels).

when I put the binary in a newer linux and try to run it, it tells "no such file or directory" error

That is happening because your binary requests /lib/ld-linux.so.2 as its program interpreter, but you likely don't have that file on your system at all (and instead have /lib/ld-linux.so.3, whatever that is).

Update:

A google search suggests that you may be compiling for an embedded ARM linux.

Your problem is not that the system you build for is older than then system you are trying to run on. Your problem is that it is different. You are building for (targeting) GLIBC (your toolchain does that), but you are running on a system with uClibc or some other libc installed.

You need to either install GLIBC on the target, or tell your toolchain to target uClibc.

Community
  • 1
  • 1
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Thank you very much for your reply! Yes I am doing it for ARM. I did not mention it because I did not even realize it matters. Please see my updated question as the comment length is limited, thank you again! – SamTest May 11 '14 at 21:49
0

The error message looks a bit strange to me.

First of all, the ld ( the dynamic linker) should be able to find exactly one library. Your error messages shows three attempts for GLIBC for example. I don't believe that your executable needs three versions to run.

The second thing is, that typically older programs run also with newer standard libraries. Especially GLIBC should work also with very old executables.

The next thing is, that I belive that you have uninstalled some libraries from your system but the library database still holds some cached informations.

I would please you to:

sudo ldconfig

to setup a correct dynamic library cache.

After that please show us the result of ldd ./test.exe

If you try to do a static link, you must have the version of the library you want to link against. If you have these libraries, you also can use it in the dynamic fashion. I can't believe that you have a .a file but not the .so file for the same library.

Or is there a misunderstanding and you use 2 systems, one you are compiling and one you are executing your binaries? If so, we will also find a solution, maybe with static linkage.

Klaus
  • 24,205
  • 7
  • 58
  • 113
  • Hi thank you very much for your reply. I am using cross compiler to compile a program on laptop UBUNTU for ARM embedded linux. It's a complicated program (for me at least) and all configurations has been setup (unfortunately targeted an older version on that ARM). I used ldconfig and this is the output: ts7800-16:~/dnp# ldconfig ldconfig: /usr/lib/libstdc++.so.6 is not a symbolic link And the output of ldd does not change anything. And also please see my updated question for more information. Thank you again! – SamTest May 11 '14 at 21:54