57

按 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
4

17 回答 17

176

如果您错误地让 Xcode 的 #import 语句自动完成功能为 'duplicate' 类指定了 '.m" 文件而不是 '.h',也可能会出现此错误。

于 2011-04-24T20:33:39.337 回答
64

您似乎在代码的不同位置两次编译相同的 BlogTableItemCell 类。在以下情况下可能会发生这种情况。

  • 您已将相同的类实现放入两个不同的文件中;

  • 您实际上只有一个此类的实现,但是您还在项目中链接了一个框架或库,其中包含一个与您的名称完全相同的类。

尝试在整个项目中找到您的班级,并确保您的项目中只有一份可用。

于 2010-02-15T07:41:16.633 回答
43

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

于 2015-11-21T16:12:37.467 回答
25

由于 const 定义不佳,我遇到了类似的问题。我在标题中定义了一个 const:

int const kCropLocationTop = 1;

这大概是多次进口的。为了解决这个问题,我更改了标题 def 如下:

extern int const kCropLocationTop;

并将 const 的分配移至 .m 文件:

int const kCropLocationTop = 1;

希望对像我一样对简单的客观 c 概念一无所知的人有所帮助!

于 2012-02-17T02:33:51.857 回答
18

iPhone:重复符号错误?由用户576924

为我正确回答。但是要找到这个 ZSH 片段有问题的 gremlin。

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

会立即告诉你你的错误在哪里。

于 2011-11-03T18:56:56.063 回答
18

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

于 2012-07-04T07:16:03.187 回答
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"

于 2013-05-30T05:33:49.710 回答
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.

于 2012-08-22T15:27:40.720 回答
3

我自己也遇到了这个问题。对于列表,这是另一种可能性:

项目文件中的重复链接行。

当我不小心复制了一行时,我在 SVN 更新中引起了这种合并冲突。

于 2011-07-07T13:17:17.483 回答
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.

于 2013-10-22T12:29:12.460 回答
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.

于 2015-02-12T23:18:07.530 回答
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.

于 2016-05-04T09:45:35.020 回答
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

于 2015-08-12T07:56:43.053 回答
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.

于 2012-09-28T17:09:49.520 回答
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.

于 2016-02-04T03:02:38.933 回答
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)

于 2016-02-11T11:04:40.240 回答
0

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

于 2017-12-18T06:54:31.537 回答