# How to nicely handle lots of "define"-related commands

This topic is 2134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,

I have a rather large application that can be compiled for Windows with MFC, for Windows with Qt, for Mac with Qt or for Linux with Qt. For historical reasons I need to keep those 4 configurations in parallel.

I define sections of code for one platform, or for one compiler with "#ifdef BLABLA #else #endif" preprocessor commands. I also have many other defines that are related to the application functionality (e.g. EVALUATION, FULL, LICENSE_CHECK, etc.).

Until now, I had all those important definitions (and new definitions based on those initial definitions) in a precompiled header. But I feel that it is not really elegant. I don't care about compilation speed anyway.

Other people are using "config.h" files, that include all the major defines. But I feel that that 2. method is prone to errors (e.g. what if I forget to include that config header in one file? The file might still be compiled, but not in the desired way and that could cause errors difficult to track.)

Is there a 3rd way? Or any good suggestions?

Thanks!

##### Share on other sites
Thanks for the quick reply MJP!

That 3rd option is a bit tricky, since I have several compilers, and on top of that, I wouldn't be able to pass-in conditional definitions, like:

 #define COMPILING_FULL VERSION //#define COMPILING_EVALUATION_VERSION #ifdef COMPILING_FULL_VERSION #define DO_LICENSE_CHECK #define INCLUDE_ADDITIONAL_FEATURES #endif #ifdef COMPILING_EVALUATION_VERSION #define DISPLAY_EVALUATION_BANNER #define FORBID_SAVING #endif 

above is a very simple example, but it shows what I need to be doing.

So, between method 1 & 2, which one would be the most appropriate, or the more conventional?

##### Share on other sites
There's another option which is usually employed in large software codebases: create a config.h and then #include that at the top of your (mandatory) PCH.

##### Share on other sites
Thanks ApochPiQ!!

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
frob
13

• 11
• 9
• 30
• 16
• 9
• ### Forum Statistics

• Total Topics
632611
• Total Posts
3007417

×