我将使用此工具链交叉编译我简单的“Hello World”程序:
arm-hisiv100-linux
然后在没有任何内置库的目标上运行 我已经使用 -static 选项
测试了我的工具链arm-hisiv100-linux-gcc HelloWorld.c -o HelloWorld-static -static
arm-hisiv100-linux-gcc HelloWorld.c -o HelloWorld
file HelloWorld-static
HelloWorld-static: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
file HelloWorld
HelloWorld: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
我的动态程序只需要运行libc.so.0(只是libuClibc-0.9.32.1.so的链接),
objdump -x HelloWorld |grep NEEDED
NEEDED libc.so.0
我在工具链的库中找到了它
file /opt/hisi-linux-nptl/arm-hisiv100-linux/target/lib/libuClibc-0.9.32.1.so
/opt/hisi-linux-nptl/arm-hisiv100-linux/target/lib/libuClibc-0.9.32.1.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked (uses shared libs), stripped
但libuClibc-0.9.32.1.so也有其动态依赖性
objdump -x /opt/hisi-linux-nptl/arm-hisiv100-linux/target/lib/libuClibc-0.9.32.1.so |grep NEEDED
NEEDED ld-uClibc.so.0
file /opt/hisi-linux-nptl/arm-hisiv100-linux/target/lib/ld-uClibc-0.9.32.1.so
/opt/hisi-linux-nptl/arm-hisiv100-linux/target/lib/ld-uClibc-0.9.32.1.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, stripped
所以我将NEEDED库的libuClibc-0.9.32.1.so'和'ld-uClibc-0.9.32.1.so'复制到目标(实际上我使用NFS),然后修改LD_LIBRARY_PATH变量。
myTarget # ls
HelloWorld HelloWorld-static HelloWorld.c libc.so.0 ld-uClibc.so.0
myTarget # chmod +x HelloWorld HelloWorld-static
myTarget # export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/
myTarget # export
export HOME='/'
export LD_LIBRARY_PATH='/usr/local/lib:/usr/lib:/mnt/mtd/share/HelloWorldProgram/'
export LOGNAME='root'
export OLDPWD='/mnt/mtd/share'
export PATH='/usr/bin:/usr/sbin:/bin:/sbin'
export PWD='/mnt/mtd/share/HelloWorldProgram'
export SHELL='/bin/sh'
export TERM='vt102'
export USER='root'
我成功运行了HelloWorld-static而不是HelloWorld
./HelloWorld-static
Hello EveryBody, this is my simple HelloWorld
./HelloWorld
-sh: ./HelloWorld: not found
我不知道我错过了什么
任何想法或帮助将不胜感激。
最好的问候
Loi Dang