příznak volby gcc -D

gcc -D definuje makro, které má použít preprocesor.

Syntax

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

Příklad

Napište zdrojový soubor myfile.c :

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

 

Sestavte soubor myfile.c a spusťte jej s definovaným DEBUG:

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

 

Nebo sestavte myfile.c a spusťte jej bez definovaného DEBUG:

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

 


Viz také

Advertising

GCC
°• CmtoInchesConvert.com •°