C语言编译过程
gcc的编译流程分为四个步骤,分别为:
・ 预编译(Pre-Processing)
・ 编译(Compiling)
・ 汇编(Assembling)
・ 链接(Linking)
-E 预编译
预编译的主要作用如下:
将源文件中以”include”格式包含的文件复制到编译的源文件中,同时将代码中没有用的注释部分删除
hello.c
//hello.c
#include <stdio.h>
int main()
{
printf("hello world\n");
return 0;
}
预编译hello.c,输出为hello.e
gcc -E -o hello.e hello.c //大写的E就是预编译
-S 编译
-S就是将C语言转化为汇编语言
gcc -S -o hello.s hello.c
-C 汇编
转为机器码
gcc -c -o hello.o hello.s
链接(Linking)
刚刚一直到这个步骤,其实代码都不能执行。
最后一步链接,需要在二进制文件 hello.o 的基础上,生成可执行文件 hello.out
gcc -o hello.out hello.o
参考链接:
http://mooc.guokr.com/note/13202/
http://blog.csdn.net/gengshenghong/article/details/7096709