C get compilation options inside the code

67 views Asked by At

I'm writing a GUI to an application, but the main developer wants to set in Makefile if the GUI get or not compiled with the rest. I'm putting all the GTK+ code in a separated file, but in the main file I need to test if the application is being compiled with the GUI or not, so how I can test this?

E.g:

if(COMPILED_WITH_GTK)
    #include "my_gtk_stuffs.h"
1

There are 1 answers

1
David Alber On BEST ANSWER

Assuming that COMPILED_WITH_GTK is an argument to the compiler command in the Makefile (in the form of -DCOMPILED_WITH_GTK) you use a preprocessor directive.

#ifdef COMPILED_WITH_GTK
#include "my_gtk_stuffs.h"
#endif

This tells the preprocessor to only process the #include statement if COMPILED_WITH_GTK is defined.

Have a look here, as well.