1.编译过程

a.预处理(进行宏替换)--

b.编译(生成汇编)--检查代码的规范性,是否有语法错误

c.汇编(生成机器可识别代码)

d.连接(生成可执行文件或库文件)


gcc -E hello.c -o hello.i 

1.-o 生成目标文件  

2.-E 只进行预处理阶段 生成.i文件

<span style="font-size:24px;"><span style="font-size:24px;">[wyg@bogon mkfile]$ gcc -E test.c -o test.i
[wyg@bogon mkfile]$ ll
total 28
-rw-rw-r--. 1 wyg wyg 65 Jul 18 07:43 Makefile
-rw-rw-r--. 1 wyg wyg 105 Jul 18 07:45 test.c
-rw-rw-r--. 1 wyg wyg 17236 Jul 18 23:11 test.i
[wyg@bogon mkfile]$ </span></span>

gcc -S hello.i -o hello.s

1.-S只进行编译 生成汇编代码

<span style="font-size:24px;"><span style="font-size:24px;">[wyg@bogon mkfile]$ gcc -S test.i -o test.s
[wyg@bogon mkfile]$ ll
total 32
-rw-rw-r--. 1 wyg wyg 65 Jul 18 07:43 Makefile
-rw-rw-r--. 1 wyg wyg 105 Jul 18 07:45 test.c
-rw-rw-r--. 1 wyg wyg 17236 Jul 18 23:21 test.i
-rw-rw-r--. 1 wyg wyg 457 Jul 18 23:21 test.s
[wyg@bogon mkfile]$
</span></span>



gcc -c hello.s -o hello.o

1.-c 将.s文件转成.o的二进制目标代码

<span style="font-size:24px;"><span style="font-size:24px;">[wyg@bogon mkfile]$ gcc -c test.s -o test.o
[wyg@bogon mkfile]$ ll
total 36
-rw-rw-r--. 1 wyg wyg 65 Jul 18 07:43 Makefile
-rw-rw-r--. 1 wyg wyg 105 Jul 18 07:45 test.c
-rw-rw-r--. 1 wyg wyg 17236 Jul 18 23:21 test.i
-rw-rw-r--. 1 wyg wyg 884 Jul 18 23:22 test.o
-rw-rw-r--. 1 wyg wyg 457 Jul 18 23:21 test.s
[wyg@bogon mkfile]$ </span></span>


gcc test.o -o test --生成test可执行文件

<span style="font-size:24px;"><span style="font-size:24px;">[wyg@bogon mkfile]$ gcc test.o -o test
[wyg@bogon mkfile]$ ll
total 44
-rw-rw-r--. 1 wyg wyg 65 Jul 18 07:43 Makefile
-rwxrwxr-x. 1 wyg wyg 4718 Jul 18 23:23 test
-rw-rw-r--. 1 wyg wyg 105 Jul 18 07:45 test.c
-rw-rw-r--. 1 wyg wyg 17236 Jul 18 23:21 test.i
-rw-rw-r--. 1 wyg wyg 884 Jul 18 23:22 test.o
-rw-rw-r--. 1 wyg wyg 457 Jul 18 23:21 test.s
[wyg@bogon mkfile]$
</span></span>



gcc使用和简要makefile_可执行文件


<span style="font-size:24px;">[wyg@bogon mkfile]$ ./test 
hello world
hello world
hello world
hello world
hello world
[wyg@bogon mkfile]$
</span>




makefile

gcc使用和简要makefile_目标文件_02

<span style="font-size:24px;">[wyg@bogon mkfile]$ ll
total 8
-rw-rw-r--. 1 wyg wyg 65 Jul 18 07:43 Makefile
-rw-rw-r--. 1 wyg wyg 105 Jul 18 07:45 test.c
[wyg@bogon mkfile]$ make
gcc -o test test.c
[wyg@bogon mkfile]$ ll
total 16
-rw-rw-r--. 1 wyg wyg 65 Jul 18 07:43 Makefile
-rwxrwxr-x. 1 wyg wyg 4718 Jul 18 23:34 test
-rw-rw-r--. 1 wyg wyg 105 Jul 18 07:45 test.c
[wyg@bogon mkfile]$ ./test
hello world
hello world
hello world
hello world
hello world
[wyg@bogon mkfile]$ make clean
rm -f test
[wyg@bogon mkfile]$ ll
total 8
-rw-rw-r--. 1 wyg wyg 65 Jul 18 07:43 Makefile
-rw-rw-r--. 1 wyg wyg 105 Jul 18 07:45 test.c
[wyg@bogon mkfile]$
</span>





gcc使用和简要makefile_预处理_03