交叉编译 -sh: ./xxx: not found 的问题

1.环境介绍

  开发板:荔枝派

  交叉编译器:arm-linux-gnueabihf-

  内核版本:linux-4.14-y

2.问题分析

执行交叉编译,生成的文件在班子内显示

# ./mygpio 
-sh: ./mygpio: not found

  (1).一般可能是没有执行权限

  (2).缺少库文件

3.解决办法

我的问题可能是2。所以

zqh@linux:~/lichee/Driver learn/LED$ arm-linux-gnueabihf-readelf -e mygpio 
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:               0x10434
  Start of program headers:          52 (bytes into file)
  Start of section headers:          15048 (bytes into file)
  Flags:                             0x5000200, Version5 EABI, soft-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:         36
  Section header string table index: 33

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .interp           PROGBITS        00010154 000154 000013 00   A  0   0  1
  [ 2] .note.ABI-tag     NOTE            00010168 000168 000020 00   A  0   0  4
  [ 3] .note.gnu.build-i NOTE            00010188 000188 000024 00   A  0   0  4
  [ 4] .gnu.hash         GNU_HASH        000101ac 0001ac 000048 04   A  5   0  4
  [ 5] .dynsym           DYNSYM          000101f4 0001f4 0000b0 10   A  6   1  4
  [ 6] .dynstr           STRTAB          000102a4 0002a4 000067 00   A  0   0  1
  [ 7] .gnu.version      VERSYM          0001030c 00030c 000016 02   A  5   0  2
  [ 8] .gnu.version_r    VERNEED         00010324 000324 000020 00   A  6   1  4
  [ 9] .rel.dyn          REL             00010344 000344 000008 08   A  5   0  4
  [10] .rel.plt          REL             0001034c 00034c 000050 08  AI  5  22  4
  [11] .init             PROGBITS        0001039c 00039c 00000c 00  AX  0   0  4
  [12] .plt              PROGBITS        000103a8 0003a8 00008c 04  AX  0   0  4
  [13] .text             PROGBITS        00010434 000434 00057c 00  AX  0   0  4
  [14] .fini             PROGBITS        000109b0 0009b0 000008 00  AX  0   0  4
  [15] .rodata           PROGBITS        000109b8 0009b8 000083 00   A  0   0  4
  [16] .ARM.exidx        ARM_EXIDX       00010a3c 000a3c 000008 00  AL 13   0  4
  [17] .eh_frame         PROGBITS        00010a44 000a44 000004 00   A  0   0  4
  [18] .init_array       INIT_ARRAY      00020f0c 000f0c 000004 00  WA  0   0  4
  [19] .fini_array       FINI_ARRAY      00020f10 000f10 000004 00  WA  0   0  4
  [20] .jcr              PROGBITS        00020f14 000f14 000004 00  WA  0   0  4
  [21] .dynamic          DYNAMIC         00020f18 000f18 0000e8 08  WA  6   0  4
  [22] .got              PROGBITS        00021000 001000 000038 04  WA  0   0  4
  [23] .data             PROGBITS        00021038 001038 000008 00  WA  0   0  4
  [24] .bss              NOBITS          00021040 001040 00000c 00  WA  0   0  4
  [25] .comment          PROGBITS        00000000 001040 00003b 01  MS  0   0  1
  [26] .ARM.attributes   ARM_ATTRIBUTES  00000000 00107b 00002a 00      0   0  1
  [27] .debug_aranges    PROGBITS        00000000 0010a5 000040 00      0   0  1
  [28] .debug_info       PROGBITS        00000000 0010e5 00089b 00      0   0  1
  [29] .debug_abbrev     PROGBITS        00000000 001980 0001a2 00      0   0  1
  [30] .debug_line       PROGBITS        00000000 001b22 0000ee 00      0   0  1
  [31] .debug_frame      PROGBITS        00000000 001c10 00009c 00      0   0  4
  [32] .debug_str        PROGBITS        00000000 001cac 001040 01  MS  0   0  1
  [33] .shstrtab         STRTAB          00000000 003970 000157 00      0   0  1
  [34] .symtab           SYMTAB          00000000 002cec 000890 10     35 101  4
  [35] .strtab           STRTAB          00000000 00357c 0003f4 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  EXIDX          0x000a3c 0x00010a3c 0x00010a3c 0x00008 0x00008 R   0x4
  PHDR           0x000034 0x00010034 0x00010034 0x00120 0x00120 R E 0x4
  INTERP         0x000154 0x00010154 0x00010154 0x00013 0x00013 R   0x1
      [Requesting program interpreter: /lib/ld-linux.so.3]
  LOAD           0x000000 0x00010000 0x00010000 0x00a48 0x00a48 R E 0x10000
  LOAD           0x000f0c 0x00020f0c 0x00020f0c 0x00134 0x00140 RW  0x10000
  DYNAMIC        0x000f18 0x00020f18 0x00020f18 0x000e8 0x000e8 RW  0x4
  NOTE           0x000168 0x00010168 0x00010168 0x00044 0x00044 R   0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x10
  GNU_RELRO      0x000f0c 0x00020f0c 0x00020f0c 0x000f4 0x000f4 R   0x1

 Section to Segment mapping:
  Segment Sections...
   00     .ARM.exidx 
   01     
   02     .interp 
   03     .interp .note.ABI-tag .note.gnu.build-id .gnu.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 .note.gnu.build-id 
   07     
   08     .init_array .fini_array .jcr .dynamic

看到我高亮的那一行:

[Requesting program interpreter: /lib/ld-linux.so.3]
接着我去板子里面找。发现并没有。所以我尝试将其拷贝到开发板的/lib/下。

接下来
./mygpio: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

看来还缺少一个库。然后我把这个库放到板子里之后我的文件系统就坏掉了。。。

============================================分割线=====================================

1.发现问题

原来是Makefile的问题,我重新写了makefile

TARGET        = myGPIO    #可执行文件名称

########################编译参数############################
CC            = arm-linux-gnueabihf-gcc 
CXX           = arm-linux-gnueabihf-g++ 
DEFINES       = 
CFLAGS        = -pipe -g -Wall -W -fPIE $(DEFINES)
CXXFLAGS      = -pipe -g -Wall -W -fPIE $(DEFINES)
INCPATH       = -I. 


########################编译文件############################
SOURCES       = ./main.c ./gpio.c
OBJECTS       = main.o gpio.o

$(TARGET) : $(OBJECTS)
        $(CC) -o $(TARGET) $(OBJECTS)
main.o : main.c gpio.h
        $(CC) $(include) $(CFLAGS) -c main.c 
gpio.o : gpio.c gpio.h 
        $(CC) $(include) $(CFLAGS) -c gpio.c 
clean :
        rm $(TARGET) $(OBJECTS)

这样make就ok了。

 
原文地址:https://www.cnblogs.com/ZQQH/p/8533631.html