嵌入式上得使用交叉编译器进行编译,这里以ARM平台的编译C程序的编译器arm-linux-gcc为例。
hello.c:
#include <stdio.h>
int main()
{
printf("Hello world!\n");
return 0;
}
1.预处理(Preprocessing):
arm-linux-gcc -E hello.c -o hello.i
生成预处理文件hello.i
2.编译(Compilation):
arm-linux-gcc -S hello.i -o hello.s
生成汇编代码hello.s,此时的汇编语言为ARM汇编指令,不是x86体系下的汇编指令
3.汇编(Assembly):
arm-linux-gcc -c hello.s -o hello.o
4.链接(Linking):
arm-linux-gcc hello.o -o hello
生成ARM平台下可以运行的可执行文件hello
若在PC机上运行则会被告知:cannot execute binary file。可以用file hello查看hello文件属性。