例子:
環境: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 通過預處理器->修改過的源碼文件
hello.i 2、
hello.i 通過編譯器->匯編代碼
hello.s 3、
hello.s 通過匯編器->浮動文件
hello.o 4、
hello.o+printf.o 通過連接器->可執行文件
hello。1、
預處理階段 預處理器(cpp)根據#后面的指令修改源代碼。例:
hello.c中的#include <stdio.h> 命令告訴預處理器把系統頭文件stdio.h插入到程序中生產另外一個C程序,一般后綴名為.i。
2、
編譯階段 編譯器(cc1)把
hello.i文件轉化成匯編代碼
hello.s文件。
3、
匯編階段 匯編器(as)把
hello.s轉化成機器語言指令浮動文件程序
hello.o。4、
連接階段 hello程序調用了標準C庫printf函數。連接器(ld)把
printf.o和hello.o連接成
hello可執行文件。
posted on 2012-05-24 14:10
canaan 閱讀(2338)
評論(2) 編輯 收藏 引用 所屬分類:
讀書筆記