Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate Symbol Error

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?

like image 878
Robert Hill Avatar asked Feb 07 '12 01:02

Robert Hill


2 Answers

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.

like image 88
quarac Avatar answered Nov 12 '22 22:11

quarac


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.

like image 26
justin Avatar answered Nov 12 '22 23:11

justin