Duplicate symbol issues

drewww picture drewww · Jul 12, 2010 · Viewed 23.8k times · Source

During a refactor of an iOS project, I ran into this bear of a bug. During the linking phase, I get this message:

ld: duplicate symbol _OBJC_IVAR_$_TinCanViewController.currentViewController in /path/to/TinCanViewController-E98A666B7AF2673A.o and /path/to/TinCanViewController-E98A666B7AF2673A.o

As far as I can tell, it looks like it claims TinCanViewController-E98A666B7AF2673A.o is declaring the specified symbol twice; both paths are pointing to the exact same .o file. I ran nm on that specific file, and it only included that symbol once:

00008150 S _OBJC_IVAR_$_TinCanViewController.currentViewController

I ran nm on all the other .o files in the directory to see if they were somehow declaring this symbol, too, but they're not. This happens to any member I add to the TinCanViewController class - it's not specific to currentViewController.

I feel like I must be somehow linking against the class twice somehow, but I've pretty assiduously gone through and checked all references to this class. In the refactored version, there are basically none. The AppDelegate includes it, but right now it's basically just a passthrough class that loads another ViewController at the start. No other classes in the project include it.

Any suggestions on what might be causing this or how I might debug it better?

Answer

Shameem picture Shameem · Apr 8, 2011

I had this issue on the latest Xcode 4. Cause: I included file.m instead of file.h

Possibly, you included TinCanViewController.m (should be TinCanViewController.h)