gcc -D option flag

gcc -D defines a macro to be used by the preprocessor.

Syntax

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

Example

Write source file myfile.c:

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

 

Build myfile.c and run it with DEBUG defined:

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

 

Or build myfile.c and run it without DEBUG defined:

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

 


See also

Write how to improve this page


email on- 00shivasharma@gmail.com
GCC
RAPID TABLES