Question

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"
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top