Duplicate Symbol Error in Objective-C build?

天涯浪子 提交于 2019-11-26 19:52:07

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.

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

NeilNie

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

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!

bradgonesurfing

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.

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

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"

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.

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.

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.

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.

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

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.

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.

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.

mrrrk

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)

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

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