I'm trying to configure cocoalumberjack and when I've added ddLogLevel
set to LOG_LEVEL_VERBOSE
XCode throws "use of undeclared identifier" error. Why is that? How to avoid?

- 1
- 16
- 47
- 69

- 6,078
- 7
- 43
- 79
4 Answers
This question indicates that clearing DerivedData
and restarting Xcode solves this kind of error.
However you should not include variables in the pre-compiled header as it will be included in every source file and prefix files are somewhat complicated compared to normal header files.
Better is to have use a Constants.h
file which contains:
extern int ddLogLevel;
and #import
that into your prefix file.
Then create an Constants.m
with:
int ddLogLevel =
#ifdef DEBUG
LOG_LEVEL_VERBOSE;
#else
LOG_LEVEL_ERROR;
#endif
This way there is only one instance of ddLogLevel
and it can be easily changed at runtime if necessary.
See this question for hints about prefix file best practices.
-
I already had `CSConstants.h` so I put the `ddLogLevel` there as suggested. – Lukasz 'Severiaan' Grela Aug 04 '14 at 07:09
-
5I think it's now DDLogLevelVerbose – Gaston Morixe Dec 07 '14 at 12:48
-
@Droppy But ddLogLevel is used by DDLogError and that kind of macros, that is, is used along all the program. Is not in that case better to add it in the PCH? Thanks. – Ricardo Feb 03 '15 at 15:17
-
1@Ricardo Well it can be *declared* in the precompiled header (using `extern`) but should be *defined* in a single source file. – Droppy Feb 04 '15 at 09:05
What solved it for me was changing #import <CocoaLumberjack/CocoaLumberjack.h>
to @import CocoaLumberjack;
, when using Xcode 8.0 for an Objective-C project.

- 17,068
- 15
- 53
- 64
-
-
-
i changed to *@import CocoaLumberjack;* but got error Module 'CocoaLumberjack' not found – famfamfam Jun 26 '21 at 07:22
Droppy’s post is correct and I recommend doing that, but I would like to address the question directly. There is a flaw in your code that may be resulting in the error.
LOG_LEVEL_VERBOSE
is defined in DDLog.h
. Your header file only imports DDLog.h
if __OBJC__
is defined, but uses LOG_LEVEL_VERBOSE
without this condition. Therefore if __OBJC__
is not defined, LOG_LEVEL_VERBOSE
will be undefined.
Why would __OBJC__
not be defined? The prefix header is prepended to C, C++, Objective-C and Objective-C++ files. Since __OBJC__
is only defined for the latter two, if there are any C or C++ files in your project then the error will occur.
Knowing this, it is clear the ddLogLevel
definition should be inside the #ifdef __OBJC__
check. However, you should do what Droppy said, and also make sure all Objective-C imports go inside the check.

- 1,537
- 10
- 14
For people who use "CocoaLumberjack 2.X" and still facing same issue after pod update, please try to import "DDLegacyMacros.h".
For prefix file users, try something like this :
#ifdef __OBJC__
...
...
#import <DDTTYLogger.h>
#import <DDLog.h>
#import <DDLegacyMacros.h>
#endif
Hope this helps someone else.

- 7,245
- 5
- 41
- 74
-
I imported CocoaLumberjack as framework and I' getting this error: "use of undeclared identifier ddloglevel". I add it #import "DDLegacyMacros.h" but I'm getting this error "DDLegacyMacros.h file not found" – user2924482 Apr 10 '17 at 17:08