1

I'm trying to figure out how to strip debug logging from my project when I build it for release and found an excellent thread here: Is it true that one should not use NSLog() on production code?

A bit below the answer another user explained how to enable/disable the DEBUG_MODE definition, so I went in exactly as explained, i.e.

In the project settings, "preprocessor macros", debug row it already read "debug=1", so I added the "debug_mode=1" to the end of the string so that it now reads "debug=1 debugmode=1" (with an ${inherited} inbetween, whatever that is...)

However, I now get a compiler yellow warning saying:

Lexical or preprocessor issue, "DEBUG_MODE" macro redefined on the row in my prefix.pch file where I added:

#define DEBUG_MODE

#ifdef DEBUG_MODE
    #define DebugLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DebugLog( s, ... ) 
#endif

If someone could explain this define issue i'd be grateful.

Community
  • 1
  • 1
Mathias
  • 3,879
  • 5
  • 36
  • 48

1 Answers1

2

Just change it to:

#ifdef DEBUG
    #define DebugLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
    #define DebugLog( s, ... ) 
#endif

Remove the #define DEBUG_MODE and remove the debugmode=1 from the "preprocessor macros" and you are good to go.

The error you where getting was due to the #define DEBUG_MODE which was already defined in the "preprocessor macros".

rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • Thanks man, that's what i did :) But i still don't understand what the warning means, is it possible for you to explain please? – Mathias Sep 20 '11 at 09:31
  • This solution doesn't quite fix it for me. I have a set of "if elif elif elifs" and in one of the cases I redefine a value which is overriding a default setting defined at the top. ...If you see what I mean. The code looks clean and seems to compile and run perfectly, but annoyingly has this warning. – Harry Wood Jun 08 '12 at 17:01