Misa
Misa

Reputation: 889

Implicit declaration of function - C99

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?

Upvotes: 36

Views: 54331

Answers (5)

Jens
Jens

Reputation: 72707

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.

Upvotes: 35

Ivan Mir
Ivan Mir

Reputation: 1239

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).

Upvotes: 1

BastiBen
BastiBen

Reputation: 19880

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>

Upvotes: 1

Mazyod
Mazyod

Reputation: 22559

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...

Upvotes: 2

JPsnowytree
JPsnowytree

Reputation: 649

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.

Upvotes: 51

Related Questions