22

I have a library that started throwing a couple linker warnings under XCode 4.4. The warnings are along the lines of "ld: warning: instance method 'methodName:' in category from overrides method from class in "

The framework still work fine, and I assume the company that wrote it will correct this in the next release, but for the time being these warnings are very annoying. Is there any way to turn them off without disabling all linker warnings?

ima747
  • 4,667
  • 3
  • 36
  • 46
  • I think it means that the people that made the library improperly subclassed some things. Doesn't seem to break anything but the linker is a little whinny about it which is annoying since I can't fix it because it's a closed source. – ima747 Aug 06 '12 at 17:53
  • Did you create/name a method in your class, same as another method in the other class? – Hexark Sep 03 '12 at 12:06
  • They aren't my classes. It's in a prebuilt library. – ima747 Sep 03 '12 at 13:11

2 Answers2

15

There are two options I have come up with by adding flags to "Other Linker Flags" in the Xcode build settings area:

1) Adding -Xlinker -w will suppress all linker warnings, no matter the type (this is the -w flag to ld(1)). Obviously that will quiet this particular warning, but all other ld warnings as well.

2) Adding -Xlinker -no_objc_category_merging will skip the optimization step where the linker combines all category methods into the base class during linking, which would then occur at runtime instead. Tiny bit slower on startup probably, but it would probably still be faster than method swizzling at runtime, and since it is during this step that ld(1) issues the warning, it will skip that too.

It appears that ld does not have a way to surgically suppress any individual warning the way the compiler does, although it has specialty flags for a couple of them or groups of them (none of which help with this one). Neither solution above is probably recommended for production code, but in some situations, one or the other might help.

Carl Lindberg
  • 2,902
  • 18
  • 22
1

If an option for hiding that warning exists it would be under:

Project Navigator(the file list on the left )-> [Project name](the one with the blue icon) -> Build Settings -> Apple LLVM compiler 3.1 - Warnings

Also:

In Xcode, how to suppress all warnings in specific source files?

Community
  • 1
  • 1
apple16
  • 1,137
  • 10
  • 13
  • 2
    Thanks for this. There's no warnings in the compiler sections that are specific to libraries or the particular warnings I'm seeing. I could turn off all warnings but that's expressly what I'm trying to avoid. The other referenced post is also for the files that will be compiled, but libraries and headers don't show there so there's no way to set flags on them specifically. I have to assume that there's no way to disable the warning in xcode since it's from the library. – ima747 Sep 04 '12 at 12:45
  • This is bad advice. I believe there are many clang warnings which do not have check boxes in the Build Settings UI. In general setting a specific `-W` option on the file will fix this problem during compilation. Set the `-fdiagnostics-show-option` option on a file and clang will tell you which `-W` to use. In this particular case, this won't work, because OP's question is about the **linker**, not the compiler. – paulmelnikow Jun 16 '13 at 01:54
  • Another solution, again for the compiler and not the linker, is diagnostic pragmas: http://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas – paulmelnikow Jun 16 '13 at 01:54
  • If you are having problems with the new xCode 7 giving you the whole 'this function overrides member but does not declare override' speil; you can add the -Wno-inconsistent-missing-override flag to "other warnings flags" in the same project build settings mentioned above – Reece Nov 04 '15 at 01:18