gcc 编译的4个过程简单识记

直入正题,测试编译代码如下:

 1 lude <stdio.h>
 2 
 3 int main()
 4 {
 5 int x=2,y,z;
 6 x*=(y=z=5);
 7 printf("%d
",x);
 8 z=3;
 9 x==(y=z);
10 printf("%d
",x);
11 x=(y==z);
12 printf("%d
",x);
13 x=(y&z);
14 printf("%d
",x);
15 x=(y&&z);
16 printf("%d
",x);
17 y=4;
18 x=(y|z);
19 printf("%d
",x);
20 x=(y||z);
21 printf("%d
",x);
22 
23 
24 return 0;
25 }
View Code

1.预处理:指令-E

gcc -E test.c -o test.i

2.编译为汇编代码:指令-S

gcc -S test.i -o test.s

3.汇编:指令 -c

gcc -c test.s -o test.o

4.链接 

gcc test.o -o test

上面是单个文件编译,如果多文件编译如下 :

gcc test1.c test2.c -o test

相当于:

gcc -c test1.c test1.o

gcc -c test2.c test2.o

gcc test1.o test2.o -o test

原文地址:https://www.cnblogs.com/ltlly/p/4123308.html