57

I got this error when I press build+debug:

ld: duplicate symbol .objc_class_name_BlogTableItemCell in /Users/fabian/Development/Workspaces/iphone_experiments/xcode_build_output/MausLog.build/Debug-iphonesimulator/MausLog.build/Objects-normal/i386/BlogTableItemCell-3733583914888A7B.o and /Users/fabian/Development/Workspaces/iphone_experiments/xcode_build_output/MausLog.build/Debug-iphonesimulator/MausLog.build/Objects-normal/i386/BlogTableItemCell-3733583914888A7B.o
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
Cœur
  • 37,241
  • 25
  • 195
  • 267
fabian
  • 5,433
  • 10
  • 61
  • 92

17 Answers17

176

You could also get this error if you mistakenly let Xcode's auto-complete for #import statements specify the '.m" file for the 'duplicate' class instead of the '.h'.

Cœur
  • 37,241
  • 25
  • 195
  • 267
64

It seems that you are compiling the same BlogTableItemCell class two times in different places of your code. This may happen in the following cases.

  • You have put the same class implementation into two different files;

  • You actually have just one implementation of this class, however you are also linking in your project a framework or library containing a class whose name is exactly the same of yours.

Try finding in the whole project your class and make sure only one copy is available within your project.

Massimo Cafaro
  • 25,429
  • 15
  • 79
  • 93
  • 1.You have put the same class implementation into two different files; -> I checked that with "Find in Project". There is only one file! 2. "linking in your project a framework or library containing a class whose name is exactly the same of yours." -> I also checked that with "Find in Project". There is only one link at the right position. Any suggest how to go from here? – fabian Feb 15 '10 at 08:32
  • 2
    Alright i got it. Xcode had an old reference to the file in the class explorer. Thanks – fabian Feb 15 '10 at 08:39
  • I had this same problem when I integrated the Facebook SDK (which included SBJson files) into a project I was using that already had those same SBJson classes. Having two copies was causing the error. Finally, I deleted one set of those files and then the problem was resolved. – Eric Brotto Nov 04 '11 at 11:28
  • 20
    Just ran into this error ... I was importing "*.m" instead "*.h" files in one of my implementations! – Christoph Jun 09 '13 at 22:44
  • 3
    I run into this problem when I make it both in the target and in the test. – huggie Dec 10 '13 at 10:47
  • Copy-pasting a class...I forgot to change the implementation name :-O – jomafer Sep 23 '14 at 15:18
  • thanks @ChristophH. ! this is a very common error it seems – Greg Aug 18 '15 at 01:49
43

For me, changing 'No Common Blocks' from Yes to No ( under Targets->Build Settings->Apple LLVM - Code Generation ) enter image description here

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
NeilNie
  • 1,050
  • 11
  • 25
25

I had a similar problem due to poor defining of consts. I had defined a const in my header:

int const kCropLocationTop = 1;

This was presumably imported multiple times. To fix i changed the header def as follows:

extern int const kCropLocationTop;

and moved the assigning of the const to the .m file:

int const kCropLocationTop = 1;

Hope that helps anyone who's as ignorant of simple objective c concepts as I am!

jsaven
  • 404
  • 1
  • 7
  • 7
18

By mistake the source file was included twice in the Project -> Build Phase -> Compile Sources. Removing one of them solved the problem.

Pratik
  • 211
  • 2
  • 3
  • Thanks, exactly what I needed. Lots of people here said the issue was things being added twice, but didn't explain how to remove it. – shim Sep 25 '12 at 05:29
  • 1
    Same problem for me. This happened following a svn merge and resolving conflicts in the project.pbxproj – Thomas Desert Nov 16 '12 at 14:02
  • THIS. How come this answer has only 9 upvotes? Seems like it's the only cause I ever run into when I get linker errors. I would like to upvote this 10 times. – KPM Apr 14 '15 at 12:30
  • Bad auto merge from git caused a dup in my project file. Another dev had renamed a bunch of files. To fix it I had to remove both copies and re-add a single copy. – Kibitz503 Nov 03 '15 at 02:47
  • Thanks !! you saved my day (y) – Bablu Joshi Aug 18 '16 at 06:16
18

iPhone: Duplicate Symbol Error? by user576924

answered it correctly for me. However to find the offending gremlin this ZSH snippet.

grep "import.*\.m" **/*.[hm]

Will immediately tell you where your error is.

Community
  • 1
  • 1
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
  • Thanks for this. I think it can be summed up as: Don't try to `#import` .m files! – Jason Moore Apr 18 '12 at 10:58
  • 1
    Could perform a similar search in Xcode. Search the whole project (Command-Shift-F) for `.m"` and `.m>`. Both should be sufficient to find the offending line. – timgcarlson Feb 12 '15 at 23:10
9

The most common reason for this error is importing an xyz.m file instead of the xyz.h file. Check if your imports contain something like #import "----.m"

JohnVanDijk
  • 3,546
  • 1
  • 24
  • 27
4

Just to add; Using Xcode to generate subclassed managed objects (Core Data) can sometimes duplicate the generated files. For me the fix was to delete the generated files and re-generate them.

ChargedNeuron
  • 311
  • 3
  • 2
3

I just ran into this problem myself. For the list, here's another possibility:

Duplicated linking line in the project file.

I caused this merging conflicts on a SVN update, when I accidentally duplicated a line.

DBD
  • 23,075
  • 12
  • 60
  • 84
2

It happened to me, too. In my case, one (just one) of my core data automatically generated classes was inserted twice. I spotted the duplication by looking at Build Phases...Compile Sources. Simply deleting one of the occurrences solved the problem.

Bruce Cichowlas
  • 336
  • 1
  • 7
2

Adding another possible cause to the list... you may have mistakingly created multiple constants in the implementation file, but outside of the implementation, with the same name.

In HeaderFileOne.m

NSString * const kCoolConstant = @"cool";

In HeaderFileTwo.m

NSString * const kCoolConstant = @"cool";

So changing one of those constant names would fix the compile error.

timgcarlson
  • 3,017
  • 25
  • 52
2

This may help someone

I got this error because I duplicate a ViewController and then renamed it. So when I compile I got this error. The reason was in both of the view controllers there was a "float" variable with same name i.e "float padding=10.0" which I had defined on class level. Renaming the name of the above mentioned variable in One of the view controllers solved my problem.

  • I have the same situation - my question is: why is this a problem? Surely two classes can have the same internal variable name... – Joe Sep 27 '17 at 09:33
1

I also faced to this problem. My solution was rename one of global variable, which has the same name as one in other class. Hope this helps

rgreso
  • 496
  • 1
  • 7
  • 19
0

The same thing happened to me while I was playing with localizable xib files, accidentally I have created two implementation files and appereantly that caused the problem in my case. After deleting / recreating the implementation file without doing the same mistake, the error was fixed.

Yunus Nedim Mehel
  • 12,089
  • 4
  • 50
  • 56
0

One of our developers left the "libSoomla*" project files in there twice. I removed the duplicate soomla files, re-built, and that fixed it!

Hope it helps.

Pim de Witte
  • 373
  • 2
  • 10
0

In may case, I followed some instructions to build a newer version of Subversion which directed me to create this symbolic link:

ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/ /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.10.xctoolchain

Now I'm really a Windows guy so it wasn't immediately obvious to me - but removing the link fixed it for me (after restarting XCode):

rm /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.10.xctoolchain

Phew.

(The actual error I got was the one described here: build error duplicate symbols arclite.o)

Community
  • 1
  • 1
mrrrk
  • 2,186
  • 20
  • 17
0

Make sure that you didn't import .m File . For me this happen I added #import "SchoolCommuterHome.m" instead of #import "SchoolCommuterHome.h"

Mehedi Hasan
  • 359
  • 3
  • 10