Duplicate symbol issues

IphoneObjective CIpadLinkerSymbols

Iphone Problem Overview


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?

Iphone Solutions


Solution 1 - Iphone

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)

Solution 2 - Iphone

I had this happen but my problem was related to merge issues from our repo. The .m file was listed twice in a spot that it should only have been listed once (within the project, but not within the file/group structure, so you could not see the issue in Xcode, only the error). The fix is opening the .pbxproj file inside your project file and locating the duplicate entry in that file. After deleting the duplicate the project built just fine.

Solution 3 - Iphone

I happened to have included the .h file and the .m file twice in the project. Once I removed the second copy, the error went away.

Solution 4 - Iphone

Make sure delegate.m is only listed once within the Compile-Sources.

Solution 5 - Iphone

This problem solve here when I deleted (using Xcode) all files .m and .h from Class folder then I cleaned Project (Command + Shift + K) and Builded again. So I drag the files from Finder to Class Folder in Xcode again. Finally, I cleaned and build my Project again...

Good Luck !!!

Solution 6 - Iphone

I think this is a bug with Apple's latest linker when creating universal static libraries. I can;t find the bug number currently, but this happens because it incorrectly generates armv6 and armv7 without disambiguating them.

To verify if this is the case, change the configuration to build only armv6 or amv7, and you won't have this problem.

Solution 7 - Iphone

This could also happen if you have a multi-target project and two targets have same file like abc.m and that abc.m is selected for both targets.

What happened in my case was I had two targets named ABC and XYZ and both had their own DiagramViewController.m file which are supposed to run code for their targets. I accidentally had DiagramViewController.m of target ABC had target selected for XYZ also.

Solution :

Click on .m file go to file inspector and unselect additional target.

enter image description here

Solution 8 - Iphone

I had a same issue. the problem was that i had two libraries that contain same .m file.

like this

lib.a - for device.

libCauly-universal.a - for simulator and device.

so i deleted one.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondrewwwView Question on Stackoverflow
Solution 1 - IphoneShameemView Answer on Stackoverflow
Solution 2 - IphonemaxpowerView Answer on Stackoverflow
Solution 3 - IphoneRamView Answer on Stackoverflow
Solution 4 - IphoneMuhammad IrfanView Answer on Stackoverflow
Solution 5 - IphoneRafael ReisView Answer on Stackoverflow
Solution 6 - IphonepsychotikView Answer on Stackoverflow
Solution 7 - Iphonerohan-patelView Answer on Stackoverflow
Solution 8 - IphoneRooneyView Answer on Stackoverflow