Duplicate symbol issues

23,963

Solution 1

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

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

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

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

Solution 5

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

Share:
23,963
drewww
Author by

drewww

Updated on March 09, 2020

Comments

  • drewww
    drewww over 4 years

    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?

  • drewww
    drewww almost 14 years
    That sounded like a super promising solution (and may help someone else), but it doesn't seem to be fixing it for me… I set all configurations to armv7 (I'm working on an iPad-only app) and I'm still seeing the error, even after build-clean. I'm pretty sure I set it properly - this is what my configuration screen looks like: web.media.mit.edu/~dharry/configuration-armv7.png Is there somewhere else I need to set it, too?
  • psychotik
    psychotik almost 14 years
    Hmm, that looks right to me. iPad can run armv6 - can you try and set it all to armv6 (and disable the "Build Active only" checkbox) and see if that helps? It shouldn't be any different than what you have, but it might be worth a shot. FWIW, I had to build the static libs that I use in my universal app as armv6 only, and Apple didn't have any issues approving it.
  • drewww
    drewww almost 14 years
    I ended up knocking out the offending class, getting it to link successfully, and then rebuilt the class from scratch (linking every step of the way) and then when I had finally put all the pieces back in and connected them up again it was fine. Mysterious. I'd test the armv6 strategy, but the repository is a happier state now and I'm in no mood to revert back to the angry-no-linking phase. Thanks for the help! Marking as answered since it seems like a good general debugging suggestion, even if my problem was some other voodoo.
  • Sam Soffes
    Sam Soffes almost 14 years
    I deleted all of my build folders for all of my static libraries and restarted Xcode. That fixed my issue. Really weird.
  • adamweeks
    adamweeks about 13 years
    Thank you! Finally found that I had accidentally imported a .m file!
  • EcksMedia
    EcksMedia over 12 years
    I am really glad I found this post. this issue has been sending me crazy and it was such a stupid thing. I did the same thing.......
  • InitJason
    InitJason almost 12 years
    I little different mix up on my part. Though the .m file only had one reference in the navigator view. The solution was that under Targets -> Build Phases -> Compiled Sources had two references to the .m file. Removed the extra reference, good to go.
  • yuf
    yuf over 11 years
    I didn't include a .m file by mistake, this was how I fixed mine, thanks!!
  • drewww
    drewww over 11 years
    Ohhhhhh, this is a great contribution. I suspect this was ACTUALLY my original problem, since my solution was to basically delete the file and reconstruct it. I bet that had the side effect of purging the file from the .pbxproj file and adding it back only once. I'd be inclined to mark yours as the official answer, but it seems like tons of people are having the .m/.h problem so I'm inclined to leave that one up there.
  • nithinreddy
    nithinreddy over 11 years
    Wow man!! You are awesome!! It helped me from wasting a hour's time
  • Johnny
    Johnny over 9 years
    Thanks a lot! saved my time!! Don't know why Xcode's autocomplete gives me .m
  • knarf
    knarf over 9 years
    wow. stared at my imports, double checking everything and still couldn't see was importing my .m file. thanks!
  • Parul Garg
    Parul Garg almost 9 years
    Thanks a lot for the solution
  • Septronic
    Septronic almost 9 years
    Freaking Genius!! You have no idea how much time you saved me!
  • iVader
    iVader over 8 years
    My project's property OTHER LINKER FLAGS had contained not only "-ObjC" but "-all_load" too! When I removed -all_load flag, problem had resolved!!
  • SuperHappy
    SuperHappy over 8 years
    Thanks a lot! saved my time
  • D4ttatraya
    D4ttatraya almost 7 years
    I had same problem, how I detected is open project file in Xcode and saw git history side-by-side and then come to know that it has double entry!