tags:

views:

111

answers:

1

Is it possible at runtime to detect if the application that is running was compiled with debug or distribution.

+1  A: 

In the Project Info, for a Debug configuration, add a Preprocessor Macro of "DEBUG" (in the GCC 4.2 - Preprocessing section).

In your code you can use #ifdef to see if DEBUG is defined if you want some code included or not for debug builds. Or you can even set a variable (I can't imagine why you would want this):

#ifdef DEBUG
  BOOL isBuiltDebug = YES;
#else
  BOOL isBuiltDebug = NO;
#endif

EDIT: Well, another way is to define a boolean value in a Preprocessor Macro, ie: "DEBUG_BUILD=1" for the Debug configuration, and "DEBUG_BUILD=0" for the Release configuration. Then you can use that value in your code:

if (DEBUG_BUILD) {
   ....
}

Just be careful not to use a macro name that could match a name that is already in your code or in any .h file that you might include either, because the preprocessor will replace it and it's a real pain to find those kinds of bugs.

progrmr
The code is going to be part of a 3rd party dist and if possible would love to avoid #ifdef, but can live with it if there is no other solution.
Steve918
I don't know another way other than using a preprocessor macro, but you can avoid the #ifdef, see my edit above.
progrmr