深入理解深入理解linux执行文件提示执行文件提示No such file or directory的背后的背后
原因原因
主要介绍了深入理解linux执行文件提示No such file or directory的背后原因,文中通过示例代码介绍的非常详
细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
1 背景背景
最近一直在研究在ZC706-ARM开发板的linux系统中弄一套编译系统(不支持apt),刚好发现公司有一套英伟达的ARM开发板且
带有ubunut系统(支持apt),此时产生一个想法,英伟达板子上编译的程序能否在ZC706的板子上运行?
2 过程过程
在英伟达的开发板中 gcc a.c生成a.out,然后拷贝到ZC706中执行出现“No such file or directory”
以前遇到的是以下原因:
文件本身不存在或者文件损坏
无执行权限 (chmod 777 xxx)
系统位数与程序位数不同
但是经过以下过程发现是ZC706缺少xx程序的指定的装载器:
1.排除文件损坏等问题-->重新生成拷贝验证
2.排除程序权限问题--> chmod 777 xx && ls -all
3.通过unanme -a 排除架构问题
4.通过readelf file 等命令对比正常执行的文件与错误执行文件的差别
验证过程:验证过程:
a.out由英伟达gcc编译生成且zc706出现上面问题 | b.out由x86 ubunut交叉编译生成且可以正常执行
后来通过google等发现装载器也会造成该现象 ,从下面可以发现两者的区别主要在于 interpreter
解决方案:解决方案:
1.统一编译器与库的关系
2. 建立软链接 ln -s /lib/ld-linux.so.3 /lib/ld-linux-armhf.so.3
3. 编译程序时,加入-static选项静态链接程序,即不使用动态库
root@tegra-ubuntu:~# readelf -h a.out
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x8315
Start of program headers: 52 (bytes into file)
Start of section headers: 4500 (bytes into file)
Flags: 0x5000402, has entry point, Version5 EABI, hard-float ABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 9
Size of section headers: 40 (bytes)
Number of section headers: 30
Section header string table index: 27
root@tegra-ubuntu:~# readelf -h b.out
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
评论0