Implicit declaration of function - C99
Asked Answered
R

5

36

I am currently using Xcode 4, and in my .pch file I have this macro: #define localize(s) NSLocalizedString((s), nil).
When I try to use this macro in some .m file, I receive this warning: Implicit declaration of function 'localize' is invalid in C99.

This code compiles without a problem, but how can I fix this so I don't get a warning?

Rotterdam answered 15/7, 2011 at 8:21 Comment(2)
I wasn't able to reproduce the issue, it compiles and runs just fine, no warnings.Overbold
It seems it was a bug in XCode... 4.0.2 I think. 4.2 betas work fine.Rotterdam
W
51

I had this problem when I did a global replace of NSLog with DLog. I foolishly included the

#define DLog(...) NSLog(...

statements, so I ended up with

#define DLog(...) DLog(...

which caused the warnings, and a linker error.

Wowser answered 12/12, 2012 at 18:25 Comment(0)
A
35

Implicit function declarations are those that the compiler sees the first time used as a function call (as opposed to those where a prototype or the function definition is seen first).

Apparently your code used localize(foo) but the macro definition was not visible. Possible reasons: you forgot to #include the file containing the localize macro or the precompilation of headers went south an did not include the localize macro so it was left unexpanded.

Acreinch answered 25/8, 2011 at 12:10 Comment(3)
But that would indicate a bug in Xcode, if the macro was defined in the project's prefix header, because that header should be precompiled and available to all compilation units (e.g. every .m file in the project). FWIW I still see this bug occasionally in Xcode 4.4.1, but quitting and relaunching Xcode fixes it.Croton
That could probably be filed under 'precompilation of headers went south'. With bugs in tools, anything can happen.Acreinch
I've seen this happen in Xcode 5. The safest way to get rid of the warning message is to simply include the relevant header file inside the file showing the error.Larder
C
2

Another "foolish" mistake I ran into was the fact that my DLog was defined in the prefix header of the iOS target, so I had to copy it over to the prefix of the OSX target, as well...

Cho answered 28/7, 2013 at 14:50 Comment(0)
C
1

I had this problem because I accidentally imported CocoaLumberjack like this:

#import <CocoaLumberjack/DDLog.h>

Apparently the CocoaLumberjack team modularized the code some more; and macros like DDLogError are now defined separately in their own header file.

I replaced the import statement with this and the error went away:

#import <CocoaLumberjack/CocoaLumberjack.h>
Caine answered 16/10, 2014 at 9:9 Comment(0)
S
1

In my case only one file was giving this error. Turned out that I added it to the project's tests target membership (in the File Inspector on the right).

Superstitious answered 29/1, 2017 at 0:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.