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?

Pascal
  • 16,846
  • 4
  • 60
  • 69
Misa
  • 889
  • 1
  • 10
  • 20

5 Answers5

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.

JPsnowytree
  • 649
  • 5
  • 6
34

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.

Jens
  • 69,818
  • 15
  • 125
  • 179
  • 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. – Mason Sep 08 '12 at 05:13
  • 2
    That could probably be filed under 'precompilation of headers went south'. With bugs in tools, anything can happen. – Jens Sep 08 '12 at 08:41
  • 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. – JaredH Jan 14 '14 at 03:26
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...

Mazyod
  • 22,319
  • 10
  • 92
  • 157
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>
BastiBen
  • 19,679
  • 11
  • 56
  • 86
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).

Ivan Mir
  • 1,209
  • 1
  • 12
  • 32