嵌入式lcd_bmp执行文件时,执行时提示无法找到文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bolvtin/article/details/52326538

参考网址

http://bbs.csdn.net/topics/390349057?page=1


root@android:/data # ls -l lcd                                                  
-rwxrwxrwx root     root         8060 2013-01-16 13:57 lcd                      
root@android:/data # ./lcd                                                      
/system/bin/sh: ./lcd: No such file or directory                                
1|root@android:/data # 


lcd是我生成的一个可执行文件,我执行它的时候居然找不到。

正常,你的程序是动态编译的,系统找不到动态链接程序!


这里以我系统上的一个打印"hello world!"的程序为例,这个是arm平台的,我X86机器上是无法执行的。
执行shell命令:
    “readelf -l hello-static”   #这个是静态编译的,编译时使用了-static选项
命令输出:

Elf file type is EXEC (Executable file)
Entry point 0x8b28
There are 6 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  EXIDX          0x077610 0x0007f610 0x0007f610 0x00768 0x00768 R   0x4
  LOAD           0x000000 0x00008000 0x00008000 0x77d7c 0x77d7c R E 0x8000
  LOAD           0x077d7c 0x00087d7c 0x00087d7c 0x00c58 0x020dc RW  0x8000
  NOTE           0x0000f4 0x000080f4 0x000080f4 0x00020 0x00020 R   0x4
  TLS            0x077d7c 0x00087d7c 0x00087d7c 0x00010 0x00028 R   0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4

 Section to Segment mapping:
  Segment Sections...
   00     .ARM.exidx 
   01     .note.ABI-tag .init .text __libc_freeres_fn __libc_thread_freeres_fn .fini .rodata __libc_subfreeres __libc_atexit __libc_thread_subfreeres .ARM.extab .ARM.exidx .eh_frame 
   02     .tdata .init_array .fini_array .jcr .data.rel.ro .got .data .bss __libc_freeres_ptrs 
   03     .note.ABI-tag 
   04     .tdata .tbss 
   05     


执行shell命令:
    “readelf -l hello-dynamic”  #这个是动态编译的
命令输出:


Elf file type is EXEC (Executable file)
Entry point 0x82c4
There are 8 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  EXIDX          0x00049c 0x0000849c 0x0000849c 0x00008 0x00008 R   0x4
  PHDR           0x000034 0x00008034 0x00008034 0x00100 0x00100 R E 0x4
  INTERP         0x000134 0x00008134 0x00008134 0x00013 0x00013 R   0x1
      [Requesting program interpreter: /lib/ld-linux.so.3]
  LOAD           0x000000 0x00008000 0x00008000 0x004a8 0x004a8 R E 0x8000
  LOAD           0x0004a8 0x000104a8 0x000104a8 0x0011c 0x00120 RW  0x8000
  DYNAMIC        0x0004b4 0x000104b4 0x000104b4 0x000e8 0x000e8 RW  0x4
  NOTE           0x000148 0x00008148 0x00008148 0x00020 0x00020 R   0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4

 Section to Segment mapping:
  Segment Sections...
   00     .ARM.exidx 
   01     
   02     .interp 
   03     .interp .note.ABI-tag .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .ARM.exidx .eh_frame 
   04     .init_array .fini_array .jcr .dynamic .got .data .bss 
   05     .dynamic 
   06     .note.ABI-tag 
   07     

看出两者的区别了么! 动态编译的程序有INTERP段,它指明了程序在加载过程中需要使用的动态链接加载器,如果指定的这个加载器未找到,那么就会提示“ No such file or directory”,如果,找到动态链接加载器,但未找到需要的库,那会有另外的提示。


关于你问题的解决操作:
使用readelf,关注“[Requesting program interpreter: /lib/ld-linux.so.3]”字段。检查目标机里该路径里有没有对应的加载器!
如果没有,你可以使用ln创建一个符号链接以指向你目标机里的动态链接加载器!目测你系统是android,这个我没玩过……

碰到相同问题,交叉编译可执行文件在arm linux执行时报找不到文件。
-static虽然能解决问题,但编译出来的可执行文件比较大。
用readelf查看动态编译的结果发现其依赖ld-linux.so.3这个库,而我的arm linux的lib下面只有一个符号链接ld-linux-armhf.so.3->arm-linux-gnueabihf/ld-2.15.so,于是新增一个符号链接ld-linux.so.3->arm-linux-gnueabihf/ld-2.15.so。
问题解决。

cd /lib

ln -s ld-2.15.so ld-linux.so.3

上面创建一个软连接 ld-linux.so.3指向了ld-2.15.so,因为在编译程序生成lcd_bmp可执行文件的时候,使用的动态库,但是这个需要ld-linux.so.3,但是arm板子的linux上没有,只有ld-2.15.so所以需要创建链接





猜你喜欢

转载自blog.csdn.net/bolvtin/article/details/52326538
今日推荐