對於gcc編譯器,有如下選項:
-d macro=string,等價於在標頭檔案中定義:#define
macro
string。例如:-d true=true,等價於:#define
true
true
-d macro,等價於在標頭檔案中定義:#define
macro
1,實際上也達到了定義:#define
macro的目的。
舉例說明:
/* hello.c */
#include #ifdef yes
char* str = "yes, this is a macro.";
#else
char* str = "no, there is no macro.";
#endif
int main()
# gcc -dyes -o helloyes hello.c
# ./helloyes
yes, this is a macro.
# gcc -o hellono hello.c
# ./hellono
no, there is no macro.
另外-u選項是取消巨集定義。
在makefile檔案裡面,
可以通過巨集定義來控制源程式的編譯。只要在makefile中的cflags中通過選項-d來指定定義的巨集即可。 如:
cflags += -dyes=1
gcc使用和簡要makefile
1.編譯過程 a.預處理 進行巨集替換 b.編譯 生成彙編 檢查 的規範性,是否有語法錯誤 c.彙編 生成機器可識別 d.連線 生成可執行檔案或庫檔案 gcc e hello.c o hello.i 1.o 生成目標檔案 2.e 只進行預處理階段 生成.i檔案 wyg bogon mkfile gc...
寫makefile時候的cc和gcc
linux 下 的 cc 和 gcc 周銀輝在linux下一會看到cc,另一會又看到gcc,感覺又點混亂的樣子。它們是同乙個東西麼,有啥區別呢 一分為二地看 首先,如果討論範圍在unix和linux之間,那麼cc和gcc不是同乙個東西。cc來自於unix的c語言編譯器,是 c compiler 的縮...
Gcc的Makefile簡單使用
makefile檔案的簡單使用 下面針對只有幾個檔案的程式來簡單試驗一下makefile 在這裡要準備四個檔案 mytool1.h ifndef mytool 1 h define mytool 1 h void mytool1 print char print str endif include ...