Xcode 4: define a preprocessor macro in a dependent target

I have an application called MyApp that is linked to the MyLibrary static library. I added the MyLibrary project to Xcode and added the MyLibrary target to MyApp target dependencies. It all works great, I can set breakpoints, and I'm very happy.

The thing is, I want to have a conditional journal in the library:

#ifdef DEBUG # define MYDebug(msg, ...) NSLog(@"\nDEBUG -> %@ \n(%s:%d)",[NSString stringWithFormat:msg, ## __VA_ARGS__], __PRETTY_FUNCTION__,__LINE__); #else # define MYDebug(msg, ...) #endif 

So, I have two build configurations for my library: - Debugging has "DEBUG = 1" in the settings of the target assembly in the "preprocessor macros", - Prod has nothing

And the target of MyLibrary is configured to build with Debug build configuration.

This works fine if I create a static library (.a) and include it in the project. But if it was created using the target dependency, it seems that DEBUG is undefined (MYDebug doesn't write anything).

I also tried setting DEBUG = 1 in the MyApp build settings, but it does not work.

Is there something I missed or another way to do this?

+6
source share
1 answer

It should just be "DEBUG" instead of "DEBUG = 1". In addition, to use a macro that needs an object assignment (NSString, etc.), you need to avoid most characters such as @ and " etc.

Here is a screenshot of the mine’s working draft from xCode 4.1:

enter image description here

+8
source

Source: https://habr.com/ru/post/892828/


All Articles