gcc -D option flag


gcc -D option flag

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



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



Write source file myfile.c:

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


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

© 2017 CalculatorX. All rights reserved.