交叉 工具链

gcc -static hello.c -o hello_x86

arm-linux-gcc -static hello.c -o hello_arm

查看文件格式:

file hello_x86

file hello_arm

可以 看到这两个 文件 所运行的 平台是不同的

-------------------------------------------

arm-linux-gcc 标准 头文件的位置:

arm-linux-gcc --help

可以看到有个选项 -print-search-dirs

arm-linux-gcc -print-search-dirs 就可以看到标准头文件的路径

----------------------------------------------

下面介绍几个工具:

1、arm-linux-ld 链接器

  arm-linx-gcc -g -c led.S  (-c 只编译 不链接)

arm-linux-ld  -Tled.lds  -o  led.elf  led.o

led.lds链接器脚本

led.elf 目标文件(要生成的文件,elf格式的文件)

led.o (arm-linx-gcc-g -c led.S 生成的文件)

2、arm-linux-readelf   elf文件工具

查看文件的所有信息

arm-linux-readelf -a led.elf

主要看输出信息的

Data:

Machine:

如果编译出来的程序在arm上运行不了,file命令查看是否是arm平台的程序,如果还是运行不了,

使用 arm-linux-readelf -a 查看,Data 会显示这个程序的大小端

arm-linux-gcc hello.c -o hello

如果hello在开发板上运行不了,排查:

file命令查看运行平台 file hello

arm-linux-readelf  -a hello 查看程序的大小端

还可能是库不对

arm-linux-readelf -d hello 查看依赖的库文件

3、 arm-linux-objdump 反汇编器

  arm-linux-gcc hello.c -o hello

  file hello

  arm-linux-objdump -D -S hello > dump.txt 把反汇编代码重定向到 dump.txt

  让反汇编代码 变简单

  arm-linux-gcc -g hello.c -o hello (加上个 -g 选项)

  arm-linux-objdump -D -S hello > dump.txt

4、arm-linux-objcopy 文件格式转换器

  把elf格式的文件转换成二进制的文件

  arm-linux-objcopy  -O  binary  led.elf led.bin

  -O  binary 表明输出的格式是 二进制

  led.elf led.bin 分别表示输入、输出文件。

原文地址:https://www.cnblogs.com/zhangxuan/p/4621901.html