Implicit declaration of function - C99

2020-02-08 05:14发布

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?

5条回答
forever°为你锁心
2楼-- · 2020-02-08 05:32

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>
查看更多
祖国的老花朵
3楼-- · 2020-02-08 05:35

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

查看更多
狗以群分
4楼-- · 2020-02-08 05:39

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.

查看更多
\"骚年 ilove
5楼-- · 2020-02-08 05:49

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.

查看更多
倾城 Initia
6楼-- · 2020-02-08 05:54

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

查看更多
登录 后发表回答