您的位置:首页 > 其它

嵌入式gcc的编译过程

2011-11-20 19:50 267 查看
嵌入式上得使用交叉编译器进行编译,这里以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文件属性。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: