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

GCC
°• CmtoInchesConvert.com •°