命令如下:
# arm-linux-gnueabihf-readelf -a linux_hello.elf
可以打印出ELF全部的信息。
如果我们只是想看看elf包含了哪些共享库,我们可以用如下命令:
# arm-linux-gnueabihf-readelf -a linux_hello.elf | grep “Shared”
这样,就过滤掉其他的line,只显示包含关键字“Shared”的line。
这个命令的作用,主要用来解决
“-/bin/sh: /usr/bin/helloworld: not found”的问题。
一开始我以为是helloworld没有运行权限,不过我给了它运行权限还是提示同样的错误。
原因是因为我没有拷helloworld所需的库文件。那怎么才能知道helloworld需要哪些库文件呢,可以这样,在命令行输入arm-linux-readelf -a helloworld 命令然后在输出的内容中找到Program Headers:节这里就有helloworld所需的库文件
看来我们需要ld-linux.so.3这个库,在交叉编译器中找到这个库文件把它拷到我们文件系统的/lib目录中然后烧到开发板中再次运行/usr/bin/helloworld结果提示“/usr/bin/helloworld: error while loading shared libraries: libgcc_s.so.1: cannot open shared object file: No such file or directory”有效果了,最起码不是前一个错误提示了,这就证明方法对头,我们看一下上面的错误这次直接提示所需的库文件了,我们按提示把libgcc_s.so.1拷到文件系统的/lib中,然后再次运行,又提示“/usr/bin/helloworld: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory”还是少库文件,我们再把这个也拷到文件系统的/lib中。
以为这样就没问题了,可是还是出现上述错误。
后来用arm-linux-readelf -a hello
输出一大堆信息,看见输出中提到了ld-linux.so.3,去库文件的目录下面查看了该文件,是个符号链接,于是把它和它指向的库文件一起复制到根文件系统的/lib目录下面,这样就可以制作的yaffs2文件系统下载到板子上。
注意:如果在BUSYBOX编译时,选择了
Build Options->
Build BusyBox as a static binary (no shared libs)
如果选择 Build BusyBox as a static binary (no shared libs) 方式进行编译时,所需的库已经编译到了busybox里面,但是自己编写的程序在文件系统上运行就没有动态库可以用了。报诸如:bin/sh: hello :not found的错误。
静态编译如:
arm-linux-gcc --static hello.c –o hello
就可以解决问题了。