【问题标题】:Compiler warning when trying to add #define DEBUG_MODE to my prefix.pch file尝试将 #define DEBUG_MODE 添加到我的 prefix.pch 文件时的编译器警告
【发布时间】:2011-09-20 09:05:54
【问题描述】:

当我构建项目以供发布时,我试图弄清楚如何从项目中去除调试日志记录,并在此处找到了一个出色的线程:Is it true that one should not use NSLog() on production code?

另一个用户解释了如何启用/禁用 DEBUG_MODE 定义的答案,所以我完全按照说明进行了操作,即

在项目设置“预处理器宏”中,调试行已读取“debug=1”,因此我将“debug_mode=1”添加到字符串末尾,使其现在读取“debug=1 debugmode= 1"(中间有一个 ${inherited},不管是什么......)

但是,我现在收到编译器黄色警告:

词法或预处理器问题,“DEBUG_MODE”宏在我添加的 prefix.pch 文件的行上重新定义:

#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

如果有人能解释这个定义问题,我将不胜感激。

【问题讨论】:

    标签: ios objective-c xcode c-preprocessor compiler-warnings


    【解决方案1】:

    只需将其更改为:

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

    从“预处理器宏”中删除 #define DEBUG_MODE 并删除 debugmode=1 你可以走了。

    你得到的错误是由于“预处理器宏”中已经定义的#define DEBUG_MODE

    【讨论】:

    • 谢谢大佬,我就是这么做的 :) 但是我还是不明白这个警告是什么意思,请问您可以解释一下吗?
    • 这个解决方案并不能完全为我解决。我有一组“if elif elif elifs”,在其中一种情况下,我重新定义了一个覆盖顶部定义的默认设置的值。 ...如果你明白我的意思。代码看起来很干净,似乎可以完美编译和运行,但令人讨厌的是这个警告。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    • 2016-12-26
    • 1970-01-01
    相关资源
    最近更新 更多