LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Conditional Compilation (https://www.linuxquestions.org/questions/programming-9/conditional-compilation-419885/)

oulevon 02-26-2006 06:47 PM

Conditional Compilation
 
Hello,

I heard that you can conditionally compile something with the #ifdef and #endif. How can I do this. I've looked online but can't find anything. Here's what I'm doing:

Code:


#ifdef DEBUG

        printf("inside DEBUG block\n");

#endif

When I compile this with gcc -DEBUG -o test test.c, the statement is never executed. Am I doing something wrong?


Thanks for any help.

paulsm4 02-26-2006 08:09 PM

You're close.

You need "-D" (like you had), and the symbol is "DEBUG". So you were off by one "D":

Quote:

gcc -DDEBUG -o test test.c
You might also wish to consider this alternate syntax:
Code:

#if defined(DEBUG)

        printf("inside DEBUG block\n");

#endif


oulevon 02-26-2006 08:12 PM

Thanks again for your help.

paulsm4 02-26-2006 08:21 PM

My pleasure!


All times are GMT -5. The time now is 03:19 AM.