linux下用gcc如何生成预处理、汇编等文件
转载:
https://www.cnblogs.com/dpf-learn/p/6127750.html
【gcc -E test.c -o test.i------>预处理文件生成.i 文件。】
-
1、c语言程序生成过程
-
C语言程序的生成过程可以简单的分为:编辑、预处理、编译、汇编、链接五个阶断。
-
下面所有的操作以hello world程序为例,源码文件命名为t.c,源码内容如下:
-
#include <stdio.h>
-
int main()
-
{
-
printf("hello world\n");
-
return 0;
-
}
-
2
2、预处理阶断
预处理阶断是对c源码中的预处理代码进行处理。
gcc -E -o t.i t.c
-
3
3、编译阶断
编译阶断是将c源码处理为汇编代码。
gcc -S -o t.s t.i
或者
gcc -S -o t.s t.c
-
4
4、汇编阶断
汇编阶断是将汇编代码处理为二进制代码。
gcc -c -o t.o t.s
或者
gcc -c -o t.o t.c
-
5
5、链接阶断
链接阶断将二进制代码打包成一个操作系统可以识别的可执行文件格式,linux是elf格式,windows上是pe格式。
gcc -o t t.o
或者
gcc -o t t.c