例子:
環(huán)境:linux
編譯器:gcc
源碼:hello.c
1 #include <stdio.h>
2
3 int main()
4 {
5 printf("hello, world\n");
6 }
:~$ gcc -o hello hello.c
1、 源碼文件
hello.c 通過預(yù)處理器->修改過的源碼文件
hello.i 2、
hello.i 通過編譯器->匯編代碼
hello.s 3、
hello.s 通過匯編器->浮動(dòng)文件
hello.o 4、
hello.o+printf.o 通過連接器->可執(zhí)行文件
hello。1、
預(yù)處理階段 預(yù)處理器(cpp)根據(jù)#后面的指令修改源代碼。例:
hello.c中的#include <stdio.h> 命令告訴預(yù)處理器把系統(tǒng)頭文件stdio.h插入到程序中生產(chǎn)另外一個(gè)C程序,一般后綴名為.i。
2、
編譯階段 編譯器(cc1)把
hello.i文件轉(zhuǎn)化成匯編代碼
hello.s文件。
3、
匯編階段 匯編器(as)把
hello.s轉(zhuǎn)化成機(jī)器語言指令浮動(dòng)文件程序
hello.o。4、
連接階段 hello程序調(diào)用了標(biāo)準(zhǔn)C庫printf函數(shù)。連接器(ld)把
printf.o和hello.o連接成
hello可執(zhí)行文件。
posted on 2012-05-24 14:10
canaan 閱讀(2344)
評論(2) 編輯 收藏 引用 所屬分類:
讀書筆記