gcc -D 選項標誌

gcc -D 定義預處理器要使用的宏。

句法

$ gcc -Dname [options] [source files] [-o output file]
$ gcc -Dname=definition [options] [source files] [-o output file]

例子

編寫源文件myfile.c

// myfile.c
#include <stdio.h>
 
void main()
{
    #ifdef DEBUG   
       printf("Debug run\n");
    #else
       printf("Release run\n");
    #endif
}

 

構建myfile.c並在定義了 DEBUG 的情況下運行它:

$ gcc -D DEBUG myfile.c -o myfile
$ ./myfile
Debug run
$

 

或者構建myfile.c並在未定義 DEBUG 的情況下運行它:

$ gcc myfile.c -o myfile
$ ./myfile
Release run
$

 


也可以看看

Advertising

海灣合作委員會
°• CmtoInchesConvert.com •°