Duplicate Symbol Error in Objective-C build?
IosObjective CDuplicate SymbolIos Problem Overview
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
Ios Solutions
Solution 1 - Ios
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'.
Solution 2 - Ios
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.
Solution 3 - Ios
For me, changing 'No Common Blocks' from Yes to No ( under Targets->Build Settings->Apple LLVM - Code Generation )
Solution 4 - Ios
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!
Solution 5 - Ios
https://stackoverflow.com/questions/2264455/iphone-duplicate-symbol-error/5773064#5773064 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.
Solution 6 - Ios
By mistake the source file was included twice in the Project -> Build Phase -> Compile Sources. Removing one of them solved the problem.
Solution 7 - Ios
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"
Solution 8 - Ios
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.
Solution 9 - Ios
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.
Solution 10 - Ios
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.
Solution 11 - Ios
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.
Solution 12 - Ios
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.
Solution 13 - Ios
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
Solution 14 - Ios
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.
Solution 15 - Ios
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.
Solution 16 - Ios
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: https://stackoverflow.com/questions/34531958/build-error-duplicate-symbols-arclite-o)
Solution 17 - Ios
Make sure that you didn't import .m File . For me this happen I added #import "SchoolCommuterHome.m" instead of #import "SchoolCommuterHome.h"