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

时间:2023-03-10 01:07:18
gcc 编译的4个过程简单识记

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

 lude <stdio.h>

 int main()
{
int x=,y,z;
x*=(y=z=);
printf("%d\n",x);
z=;
x==(y=z);
printf("%d\n",x);
x=(y==z);
printf("%d\n",x);
x=(y&z);
printf("%d\n",x);
x=(y&&z);
printf("%d\n",x);
y=;
x=(y|z);
printf("%d\n",x);
x=(y||z);
printf("%d\n",x); return ;
}

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

相关文章