重复的符号错误

时间:2012-02-07 01:43:28

标签: objective-c xcode

我不确定我做了什么,但我添加了一个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

我尝试退出更改以添加IBOutlet,但我仍然收到此错误消息。

我检查了其他类似的帖子,但我不认为条件是相同的(虽然我可能是错的)。有什么想法吗?

11 个答案:

答案 0 :(得分:51)

我遇到了类似的问题:

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)

最后原因是在MyClass2.m中我写道:

#include "MyClass1.m"

而不是

#include "MyClass1.h"

当你的.m文件中有很多#include语句时,很难找到。

答案 1 :(得分:20)

当在目标中编译源两次,或者它是在两个单独的目标中构建时,可能会发生这种情况。您可以在目标的构建阶段验证这一点,或者从目标中删除它,然后重新添加它。

<强>更新

Kasas指出了一个新的Xcode功能(在其他评论者拒绝的编辑中),Xcode可以为您检测一些此类情况 - 只需“验证”目标或项目设置。如果找到,Xcode将为您提供删除冗余编译。谢谢卡萨斯。

答案 2 :(得分:11)

除.m问题外,如果您在错误的文件夹中创建模型,则删除它们,然后在正确的文件夹中创建/替换模型。您可能需要删除已编译的来源分组下的目标构建阶段中的重复项。

答案 3 :(得分:3)

我有这个问题。我解决了

因为ı导入到viewcontroller时出错了。

错误:#import“viewcontroller。 m

后来我编辑:`#import“viewcontroller。 h

只有我更改了viewcontroller的扩展名。

答案 4 :(得分:2)

在我的第一个应用中,我在更换课程后遇到了这个问题。由于我不想完全删除旧类,我将其移动到另一个组,仍然在xcode中。 xcode尝试编译此类的两个副本,从而导致错误。从项目中删除对旧类的引用修复了我的问题。

Upvote去了quarac,让我更容易发现。

答案 5 :(得分:1)

不确定,但是一个愚蠢的问题 - 清除旧代码后你做了干净吗?有时那些东西会挂起来。

答案 6 :(得分:1)

如果多个类共享 同名 ,则会出现此类错误

答案 7 :(得分:0)

这可能是因为您包含了两个Inspection

的源文件

答案 8 :(得分:0)

我真的不明白为什么这会是一个问题,所以也许有人可以澄清,但对我来说问题是我有导入另一个已声明实例变量具有相同名称的类作为当前班级中的一员。

当我在导入的类的实现中更改了ivar的名称时,错误消失了。

希望这有帮助!

答案 9 :(得分:0)

如果在两个不同的类中具有相同名称的常量定义,也可能发生这种情况。在我的例子中,它是一个像这样的布尔标志:

A类:

#import "MyATableViewController.h"

@implementation MyATableViewController

@synthesize someVariable;

BOOL MY_FLAG = YES;
...

B组:

#import "MyBTableViewController.h"

@implementation MyBTableViewController

@synthesize someVariable;

BOOL MY_FLAG = YES;
...

我只需要将第二类的常量定义更改为:

... BOOL MY_B_FLAG = YES; ...

答案 10 :(得分:0)

我遇到了同样的问题,我解决了它。 当我复制并粘贴我的视图并使用不同的名称查看控制器时,我收到此错误(在_temp中使用sembate sembol)。我通过改变常量名称解决了这个错误。您还可以在实现支撑之间移动常量。我的示例代码如下。我不变的名字是临时的。

    @implementation MyCombineSaveTableView
{
    BOOL *pulltoRefResh;
    NSString *currentElement;
    int temp;
    int User_ID;
}