xcode 重复符号错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9169944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Duplicate Symbol Error
提问by Robert Hill
I'm not sure what I did but I added an IBOutlet to display an additional attribute in a TableView cell. When building the application I get the following error message...
我不确定我做了什么,但我添加了一个 IBOutlet 以在 TableView 单元格中显示附加属性。构建应用程序时,我收到以下错误消息...
Ld /Users/roberthill/Library/Developer/Xcode/DerivedData/PHAInspect-awfhtfopjdgfmsdsjfjivdnlzgir/Build/Products/Debug-iphonesimulator/PHAInspect.app/PHAInspect normal i386
cd /Users/roberthill/Documents/PHAInspect
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -L/Users/roberthill/Library/Developer/Xcode/DerivedData/PHAInspect-awfhtfopjdgfmsdsjfjivdnlzgir/Build/Products/Debug-iphonesimulator -F/Users/roberthill/Library/Developer/Xcode/DerivedData/PHAInspect-awfhtfopjdgfmsdsjfjivdnlzgir/Build/Products/Debug-iphonesimulator -filelist /Users/roberthill/Library/Developer/Xcode/DerivedData/PHAInspect-awfhtfopjdgfmsdsjfjivdnlzgir/Build/Intermediates/PHAInspect.build/Debug-iphonesimulator/PHAInspect.build/Objects-normal/i386/PHAInspect.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50000 -framework CoreData -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/roberthill/Library/Developer/Xcode/DerivedData/PHAInspect-awfhtfopjdgfmsdsjfjivdnlzgir/Build/Products/Debug-iphonesimulator/PHAInspect.app/PHAInspect
ld: duplicate symbol _OBJC_METACLASS_$_Inspection in /Users/roberthill/Library/Developer/Xcode/DerivedData/PHAInspect-awfhtfopjdgfmsdsjfjivdnlzgir/Build/Intermediates/PHAInspect.build/Debug-iphonesimulator/PHAInspect.build/Objects-normal/i386/Inspection-AEDA73D75B42426A.o and /Users/roberthill/Library/Developer/Xcode/DerivedData/PHAInspect-awfhtfopjdgfmsdsjfjivdnlzgir/Build/Intermediates/PHAInspect.build/Debug-iphonesimulator/PHAInspect.build/Objects-normal/i386/Inspection-AEDA73D75B42426A.o for architecture i386
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed with exit code 1
I tried backing out the changes to add the IBOutlet but I'm still getting this error message.
我尝试取消更改以添加 IBOutlet,但我仍然收到此错误消息。
I checked other similar posts but I don't think the conditions are the same (I could be wrong though). Any ideas?
我检查了其他类似的帖子,但我认为条件不一样(虽然我可能是错的)。有任何想法吗?
回答by quarac
I had a similar issue:
我有一个类似的问题:
ld: duplicate symbol _OBJC_METACLASS_$_MyClass1 in /Users/.../MyClass2.o and /Users/.../MyClass1.o for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And finally the reason was that inside MyClass2.m I wrote:
最后的原因是在 MyClass2.m 中我写道:
#include "MyClass1.m"
Instead of
代替
#include "MyClass1.h"
It's hard to find when you have a lot of #include statements inside your .m file.
当您的 .m 文件中有很多 #include 语句时,很难找到。
回答by justin
This can happen when a source is compiled in your target twice, or if it is built in two separate targets. You can verify this in your target's build phases, or remove it from the target and then re-add it.
当一个源在您的目标中编译两次,或者如果它是在两个单独的目标中构建时,就会发生这种情况。您可以在目标的构建阶段验证这一点,或者将其从目标中删除,然后重新添加。
Update
更新
Kasas pointed out a new Xcode feature (in an Edit which other reviewers rejected), where Xcode can detect some such cases for you -- Simply "Validate" the target or project settings. If found, Xcode will offer to remove the redundant compilation for you. Thanks Kasas.
Kasas 指出了一个新的 Xcode 功能(在其他审阅者拒绝的编辑中),其中 Xcode 可以为您检测一些此类情况——只需“验证”目标或项目设置。如果找到,Xcode 会为您删除多余的编译。谢谢卡萨斯。
回答by RobCroll
Other than the .m issue, if you created models in the wrong folder, deleted them and then created/replaced the models in the correct folder. You may need to remove the duplicates in Targets Build Phasesunder the Compiled Sourcesgrouping.
除了 .m 问题,如果您在错误的文件夹中创建了模型,请删除它们,然后在正确的文件夹中创建/替换模型。您可能需要在Compiled Sources分组下的Targets Build Phases 中删除重复项。
回答by Erhan Demirci
I had this problem . I solve it.
我有这个问题。我解决了
Because ? did mistake when ? import to viewcontroller .
因为 ?什么时候弄错了?导入到视图控制器。
mistake: #import "viewcontroller.m"
错误:#进口“视图-控制米”
Later I edit : `#import "viewcontroller.h"
后来我编辑:`#进口“视图-控制^ h”
only I changed extension of viewcontroller .
只有我更改了 viewcontroller 的扩展名。
回答by Dan Power
In my first app, I had this problem after replacing a class. As I didn't want to delete the old class completely, I moved it to another group, still within xcode. xcode tries to compile two copies of this class, causing the error. Deleting the references to the old class from the project fixed my problem.
在我的第一个应用程序中,我在替换一个类后遇到了这个问题。由于我不想完全删除旧类,我将它移到另一个组,仍然在 xcode 中。xcode 尝试编译此类的两个副本,从而导致错误。从项目中删除对旧类的引用解决了我的问题。
Upvote went to quarac, who made this easier for me to spot.
Upvote去了quarac,他让我更容易发现。
回答by drekka
Not sure, but a silly question - did you do a clean after clearing the old code? Sometimes that stuff hangs around.
不确定,但一个愚蠢的问题 - 您在清除旧代码后是否进行了清理?有时这些东西会一直存在。
回答by Durai Amuthan.H
If more than one class shares a same namethis kind of error will come
如果多个类共享相同的名称,则会出现这种错误
回答by Emre Gürses
i had meet same problem, and i solved it. When i copy and paste my view and view controller with different name, i got this error (dublicate sembol in _temp). i solved this error by changing constant name. You can also move your constant between implemantation bracets. My examples code below. And my constant name is temp.
我遇到了同样的问题,我解决了。当我用不同的名称复制并粘贴我的视图和视图控制器时,出现此错误(_temp 中的重复符号)。我通过更改常量名称解决了这个错误。您还可以在实施括号之间移动常量。我的示例代码如下。我的常量名称是 temp。
@implementation MyCombineSaveTableView
{
BOOL *pulltoRefResh;
NSString *currentElement;
int temp;
int User_ID;
}
回答by Inder Kumar Rathore
This might b due to the reason that you have included two source files of Inspectionclass
这可能是因为您包含了两个Inspection类的源文件
回答by bkbeachlabs
I dont really understand why this would be a problem so maybe someone could clarify but for me the problem was that I had importedanother class which had declared an instance variable with the same nameas one in the current class.
我真的不明白为什么这会是一个问题,所以也许有人可以澄清一下,但对我来说,问题是我导入了另一个类,该类声明了一个与当前类中同名的实例变量。
When I changed the name of the ivar in the imported class's implementation the error disappeared.
当我在导入的类的实现中更改 ivar 的名称时,错误消失了。
Hope this helps!
希望这可以帮助!

