What can be the cause of "use of undeclared identifier LOG_LEVEL_VERBOSE" message
Asked Answered
F

4

15

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?

enter image description here

Feinstein answered 4/8, 2014 at 6:25 Comment(0)
R
8

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.

Rosabelle answered 4/8, 2014 at 6:47 Comment(3)
I think it's now DDLogLevelVerboseExtravagant
@Rosabelle 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.Jailbird
@Jailbird Well it can be declared in the precompiled header (using extern) but should be defined in a single source file.Rosabelle
D
6

What solved it for me was changing #import <CocoaLumberjack/CocoaLumberjack.h> to @import CocoaLumberjack;, when using Xcode 8.0 for an Objective-C project.

Darell answered 16/10, 2016 at 9:46 Comment(2)
I am using CocoapodsDarell
i changed to @import CocoaLumberjack; but got error Module 'CocoaLumberjack' not foundAiaia
L
2

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.

Luster answered 14/4, 2015 at 12:40 Comment(0)
D
1

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.

Delvalle answered 14/4, 2015 at 11:34 Comment(1)
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"Proteiform

© 2022 - 2024 — McMap. All rights reserved.