Duplicate Symbol Error in Objective-C build?

匆匆过客 提交于 2019-11-26 07:27:11

问题


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

回答1:


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.




回答2:


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'.




回答3:


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




回答4:


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!




回答5:


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.




回答6:


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




回答7:


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"




回答8:


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.




回答9:


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.




回答10:


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.




回答11:


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.




回答12:


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




回答13:


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.




回答14:


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.




回答15:


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.




回答16:


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)




回答17:


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



来源:https://stackoverflow.com/questions/2264455/duplicate-symbol-error-in-objective-c-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!