Duplicate Symbol Error

2020-04-03 16:24发布

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

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.

I checked other similar posts but I don't think the conditions are the same (I could be wrong though). Any ideas?

11条回答
时光不老,我们不散
2楼-- · 2020-04-03 16:47

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:

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

查看更多
仙女界的扛把子
3楼-- · 2020-04-03 16:50

I had this problem . I solve it.

Because ı did mistake when ı import to viewcontroller .

mistake: #import "viewcontroller.m"

Later I edit : `#import "viewcontroller.h"

only I changed extension of viewcontroller .

查看更多
小情绪 Triste *
4楼-- · 2020-04-03 16:51

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.

查看更多
【Aperson】
5楼-- · 2020-04-03 16:51

This might b due to the reason that you have included two source files of Inspection class

查看更多
▲ chillily
6楼-- · 2020-04-03 16:52

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.

    @implementation MyCombineSaveTableView
{
    BOOL *pulltoRefResh;
    NSString *currentElement;
    int temp;
    int User_ID;
}
查看更多
登录 后发表回答