C語言 g 常用編譯選項備忘

2021-07-09 05:12:57 字數 800 閱讀 3780

不加引數: gcc test.c 生成可執行檔案 a.out

(預設生成可執行檔案)

-o : 生成指定的檔名 (例子: gcc -o test test.c , 生成可執行檔案 test )

-c : 生成目標檔案 (例子: gcc -c test.c , 生成目標檔案 test.o )

-c -o : 生成指定檔名的目標檔案 (例子: gcc -c -o hello.o test.c , 生成目標檔案 hello.o )

一條命令可以編譯多個原始檔生成目標檔案:

gcc -c test1.c test2.c 將生成 test1.o test2.o

多個原始檔編譯成乙個執行檔案:

gcc -o test test1.c test2.c 將生成 test

先生成目標檔案,再連線成可執行檔案:

gcc -c test1.c test2.c 將生成 test1.o test2.o

gcc -o test test1.o test2.o 將生成 test

其他:-e: 進行預編譯

-s: 編譯成組合語言

-wno-deprecated: 用於忽略標頭檔案信賴的警告

ar -rcs libstr.a string.o –> 把string.o打包為庫檔案libstr.a

gcc -o test main.c libstr.a

或者:gcc -o test main.c -l str (str為庫名,它不包含函式庫lib和副檔名.a, -l鏈結的庫名要在-o的目的名稱之前)

動態鏈結庫的使用跟靜態鏈結庫一樣。

01 g 編譯器常用選項

gcc gnu compiler collection gnu編譯器套件集合 gcc gcc中的c編譯器 g gcc中的c 編譯器 eg e hello.cpp o hello.i 預處理 preprocessing 生成.i檔案 sg s hello.i o hello.s 編譯 compilat...

g 的編譯選項 Wl, rpath

假設main.cpp,hello.h,hello.cpp,其中main.cpp呼叫了hello類中的方法 1 生成hello.so g shared hello.cpp olibhello.so 2 編譯main.cpp,並鏈結,並指定執行時libhello.so的位置 g main.cpp lhe...

c編譯選項

unix系統高階程式設計 uc 15 unix系統函式為主 大量的unix系統呼叫 unix系統的原理 記憶體如何管理,程序如何設計 培養大家的動手能力 能做一些有實際意義的軟體 商業開發 建議 1.多動手,多寫程式,為現在招工作更方便。2.有機會一定提公升自己的學歷,最好28,29歲左右開始公升研...