Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve "error while loading shared libraries" when trying to run an arm binary with qemu-arm?

Tags:

qemu

arm

I'm running Linux Mint 14 with qemu, qemu-user, and the gnueabi toolchain installed. I compiled test.c with arm-linux-gnueabi-gcc test.c -o test.

When I try and run qemu-arm /usr/arm-linux-gnueabi/lib/ld-linux.so.3 test

I get an error saying: test: error while loading shared libraries: test: cannot open shared object file: No such file or directory. Running qemu-arm test, as I've previously tried, gives /lib/ld-linux.so.3: No such file or directory

However, the file does exist and is reachable.

$ stat /usr/arm-linux-gnueabi/lib/ld-linux.so.3
  File: `/usr/arm-linux-gnueabi/lib/ld-linux.so.3' -> `ld-2.15.so'
  Size: 10          Blocks: 0          IO Block: 4096   symbolic link
Device: 801h/2049d  Inode: 4083308     Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-04-22 16:19:48.090613901 -0700
Modify: 2012-09-21 08:31:29.000000000 -0700
Change: 2013-04-22 15:58:41.042542851 -0700
 Birth: -

Does anyone know how I can make qemu run an arm program without having to emulate an entire arm Linux kernel?

test.c is

#include <stdio.h>
int main() {
    printf("this had better work\n");
}

and file test is

test: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, BuildID[sha1]=0xf2e49db65394b77c77ee5b65b83c0cc9220cbfc0, not stripped
like image 420
David Avatar asked Apr 23 '13 00:04

David


4 Answers

you can run the example by providing a path to the arm-linux-gnueabi shared libs using the -L flag.

qemu-arm -L /usr/arm-linux-gnueabi/

also make sure the LD_LIBRARY_PATH is not set.

unset LD_LIBRARY_PATH
like image 79
vivek_v Avatar answered Nov 19 '22 01:11

vivek_v


$ export QEMU_LD_PREFIX=/usr/arm-linux-gnueabi

This works for me. It's basically the same thing as:

$ qemu-arm -L /usr/arm-linux-gnueabi/

You can add it to the ~/.bashrc file so you don't have to type it everytime you open the terminal.

like image 26
Mita_ Avatar answered Nov 19 '22 00:11

Mita_


I also met this problem when running a C program with assembly code. My solution is to build the executable with the option "-static", for instance

arm-linux-gnueabi-gcc -static -g main.c square.s

Then

qemu-arm a.out

will not report the error saying "can not find the /lib/ld-linux.so.3".

The only drawback is that the executable could be with a large size. But it's helpful when you just want to test your code.

Of course, you can go with the method from Balau(see artless noise's answer). But if you don't want to feel frustrated by something like "UART serial ports" in this step, which is only to run a simple "test" function, go for a try of my fix.

like image 12
Ning Avatar answered Nov 19 '22 00:11

Ning


I solved the problem by copying the following libraries into /lib but I believe there should be a way better solution rather than this nasty solution I invented!

sudo cp  /usr/arm-linux-gnueabi/lib/ld-linux.so.3 /lib
sudo cp /usr/arm-linux-gnueabi/lib/libgcc_s.so.1 /lib
sudo cp /usr/arm-linux-gnueabi/lib/libc.so.6 /lib

Please let me know if there are other better solutions as I am interested to know.

like image 5
Mona Jalal Avatar answered Nov 18 '22 23:11

Mona Jalal