1. 程式人生 > >gcc 常用編譯選項

gcc 常用編譯選項

應用程序 默認 ron 一個 linu str 技術 出錯 arm

gcc 和 arm-linux-gcc的常用選項

gcc 的使用方法:

gcc 【選項】 文件名

gcc常用選項:

  -v:查看gcc 編譯器的版本,顯示gcc執行時的詳細過程

  -o < file > Place the output into < file >

          指定輸出文件名為file,這個名稱不能跟源文件名同名  

  -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 -v: 查看 gcc 編譯器的版本

方式1:

gcc hello.c 輸出一個 a.out,然後 ./a.out 來執行該應用程序

gcc -o hello hello.c 輸出hello ,然後 ./hello 來執行該應用程序。

方式2:

gcc -E -o hello.i hello.c

gcc -S -o hello.s hello.i

gcc -c -o hello.o hello.s

gcc -o hello hello.o

.o: object file (OBJ文件)

小結:

1)輸入文件的後綴名和選項共同決定gcc到底執行哪些操作。

技術分享圖片

2)在編譯過程中,除非使用了-E、-S、-C選項(或者編譯出錯阻止了完整的編譯過程)

  否則最後的步驟都是鏈接。

方式3:

gcc -c -o hello.o hello.s

gcc -o hello hello.o

gcc會對.c文件默認進行預處理操作, -c再來指明了編譯、匯編,從而得到.o文件

再通過gcc -o hello hello.o 將.o文件進行鏈接,得到可執行應用程序。

gcc 常用編譯選項