Objective-C 构建中出现重复符号错误?
当我按构建+调试时出现此错误:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
如果您错误地让 Xcode 的 #import 语句自动完成功能为“重复”类指定“.m”文件而不是“.h”,您也可能会收到此错误。
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'.
您似乎在代码的不同位置编译了相同的 BlogTableItemCell 类两次。在以下情况下可能会发生这种情况。
您已经安排了相同的课程
实现为两个不同的
文件;
你实际上只有一个
然而这个类的实现
您还在项目中链接了一个框架
或包含一个类的库,其
名字和你的一模一样。
尝试在整个项目中查找您的班级,并确保您的项目中只有一份可用。
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.
对我来说,将“无公共块”从“是”更改为“否”(在 Targets->Build Settings->Apple LLVM - Code Generation 下)
For me, changing 'No Common Blocks' from Yes to No ( under Targets->Build Settings->Apple LLVM - Code Generation )
由于常量定义不明确,我遇到了类似的问题。
我在标头中定义了一个 const:
这可能被导入了多次。为了解决这个问题,我更改了头文件 def,如下所示:
并将 const 的分配移至 .m 文件:
希望这对像我一样对简单 Objective C 概念一无所知的人有所帮助!
I had a similar problem due to poor defining of consts.
I had defined a const in my header:
This was presumably imported multiple times. To fix i changed the header def as follows:
and moved the assigning of the const to the .m file:
Hope that helps anyone who's as ignorant of simple objective c concepts as I am!
user576924 的 iPhone:重复符号错误?
为我正确回答了。然而,要找到这个 ZSH 片段中令人讨厌的 gremlin。
会立即告诉你你的错误在哪里。
iPhone: Duplicate Symbol Error? by user576924
answered it correctly for me. However to find the offending gremlin this ZSH snippet.
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.
出现此错误的最常见原因是导入 xyz.m 文件而不是 xyz.h 文件。
检查您的导入是否包含类似内容
#import "----.m"
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"
只是添加;使用 Xcode 生成子类托管对象(核心数据)有时会重复生成的文件。对我来说,修复方法是删除生成的文件并重新生成它们。
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.
我自己刚刚遇到了这个问题。对于列表,还有另一种可能性:
项目文件中的重复链接行。
当我不小心重复了一行时,我在 SVN 更新中导致了这种合并冲突。
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.
将另一个可能的原因添加到列表中...您可能错误地在实现文件中创建了多个常量,但在实现之外,具有相同的名称。
In HeaderFileOne.m
In HeaderFileTwo.m
因此,更改这些常量名称之一将修复编译错误。
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
In HeaderFileTwo.m
So changing one of those constant names would fix the compile error.
这可能会帮助
我收到此错误的人,因为我复制了 ViewController,然后重命名了它。所以当我编译时我得到了这个错误。原因是在两个视图控制器中都有一个具有相同名称的“float”变量,即我在类级别定义的“float padding=10.0”。
在视图控制器之一中重命名上述变量的名称解决了我的问题。
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 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
当我使用可本地化的 xib 文件时,同样的事情也发生在我身上,我不小心创建了两个实现文件,显然这导致了我的情况的问题。删除/重新创建实现文件而没有犯同样的错误后,错误得到修复。
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.
我们的一位开发人员将“libSoomla*”项目文件留在那里两次。我删除了重复的 soomla 文件,重新构建,然后修复了它!
希望有帮助。
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.
在可能的情况下,我按照一些说明构建了较新版本的 Subversion,这些说明指示我创建此符号链接:
现在我真的是一个 Windows 用户,所以它对我来说并不是很明显 - 但删除该链接为我修复了它(重新启动 XCode 后):
唷。
(我得到的实际错误是这里描述的错误:
构建错误重复符号arclite.o)
In may case, I followed some instructions to build a newer version of Subversion which directed me to create this symbolic link:
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):
Phew.
(The actual error I got was the one described here:
build error duplicate symbols arclite.o)
确保您没有导入 .m 文件。对我来说,发生这种情况我添加了#import“SchoolCommuterHome.m”而不是#import“SchoolCommuterHome.h”
Make sure that you didn't import .m File . For me this happen I added #import "SchoolCommuterHome.m" instead of #import "SchoolCommuterHome.h"