1.gcc有引數可以很好的理解編譯的過程.
-e preprocess only; do not compile, assemble or link
-s compile only; do not assemble or link
-c compile and assemble, but do not link
gcc 從語言編譯全過程 預處理---->編譯---->彙編----->鏈結
以下部分摘錄網上文章:
1)預處理(pre-processing)
在該階段,編譯器將c源**中的包含的標頭檔案如stdio.h編譯進來,使用者可以使用gcc的選項」-e」進行檢視。
用法:
gcc -e hello.c -o hello.i
作用:將hello.c預處理輸出hello.i檔案。
2)編譯階段(compiling)
第二步進行的是編譯階段,在這個階段中,gcc首先要檢查**的規範性、是否有語法錯誤等,以確定**的實際要做的工作,在檢查無誤後,gcc把**翻譯成組合語言。使用者可以使用」-s」選項來進行檢視,該選項只進行編譯而不進行彙編,生成彙編**。
選項 -s 用法:
gcc –s hello.i –o hello.s
作用:將預處理輸出檔案hello.i彙編成hello.s檔案。
3)彙編階段(assembling)
彙編階段是把編譯階段生成的」.s」檔案轉成二進位制目標**.
選項 -c 用法:
gcc –c hello.s –o hello.o
作用:將彙編輸出檔案test.s編譯輸出test.o檔案。
gcc hello.o –o hello.exe
參考:
GCC編譯常用命令
加入新公司後,基本上是一鍵式打包指令碼,對於gcc基本上快忘了,重新拾起。gcc命令提供了非常多的命令選項,但並不是所有都要熟悉,初學時掌握幾個常用的就可以了,到後面再慢慢學習其它選項,免得因選項太多而打擊了學習的信心。一.常用編譯命令選項 假設源程式檔名為test.c。1.無選項編譯鏈結 用法 g...
gcc編譯命令
一 gcc的編譯過程分為四個過程 1.預處理 也稱預編譯,preprocessing 生成.i的檔案 2.編譯 compilation 將預處理後的檔案轉換成組合語言,生成.s檔案 3.彙編 assembly 彙編變為目標 機器 生成.o的檔案 4.鏈結 linking 連線目標 生成可執行程式 二...
gcc編譯命令
命令 gcc main.cpp 命令 gcc main.cpp o demo 命令 gcc e main.cpp o main.i 作用 將main.cpp預處理輸出main.i檔案。命令 gcc s main.i 作用 將預處理輸出檔案main.i彙編成main.s檔案。命令 gcc c main...