Xcode 4:在依赖目标中定义预处理器宏

时间:2021-11-02 07:12:10

I have an app named MyApp which is linked to a static library MyLibrary I've added the MyLibrary project to Xcode and added the MyLibrary target to MyApp's target dependencies. All this works fine, I can set breakpoints, and I'm pretty happy.

我有一个名为MyApp的应用程序链接到静态库MyLibrary我已将MyLibrary项目添加到Xcode,并将MyLibrary目标添加到MyApp的目标依赖项。这一切都很好,我可以设置断点,我很高兴。

The thing is that I want a conditional log 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 configuration for my library : - Debug has "DEBUG=1" in the target's build settings in "preprocessor macros" - Prod has nothing

所以我的库有两个构建配置: - 调试在“预处理器宏”的目标构建设置中有“DEBUG = 1” - Prod什么都没有

And the MyLibrary target is set to build with the Debug build configuration.

并且MyLibrary目标设置为使用Debug构建配置构建。

This works fine if I build the static library (.a), and include it in a project. But if it is built by target dependency, it seems that DEBUG is not defined (MYDebug doesn't log anything).

如果我构建静态库(.a)并将其包含在项目中,这可以正常工作。但是如果它是由目标依赖构建的,那么似乎没有定义DEBUG(MYDebug不记录任何东西)。

I've also tried to set DEBUG=1 in MyApp's build settings, but it doesn't work.

我也尝试在MyApp的构建设置中设置DEBUG = 1,但它不起作用。

Is there something I missed, or another way to do it ?

有没有我错过的,或其他方式去做?

1 个解决方案

#1


8  

It should just be "DEBUG" instead of "DEBUG=1". Also, to use a macro that needs an Object assignment (NSString, etc) you need to escape most of the characters like @ and " etc..

它应该只是“DEBUG”而不是“DEBUG = 1”。此外,要使用需要对象赋值(NSString等)的宏,您需要转义大多数字符,如@和“等等。

Here is a screenshot of a working project of mine from xCode 4.1:

以下是xCode 4.1中我的工作项目的屏幕截图:

Xcode 4:在依赖目标中定义预处理器宏

#1


8  

It should just be "DEBUG" instead of "DEBUG=1". Also, to use a macro that needs an Object assignment (NSString, etc) you need to escape most of the characters like @ and " etc..

它应该只是“DEBUG”而不是“DEBUG = 1”。此外,要使用需要对象赋值(NSString等)的宏,您需要转义大多数字符,如@和“等等。

Here is a screenshot of a working project of mine from xCode 4.1:

以下是xCode 4.1中我的工作项目的屏幕截图:

Xcode 4:在依赖目标中定义预处理器宏