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条回答
Explosion°爆炸
2楼-- · 2020-04-03 16:34

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.

Upvote went to quarac, who made this easier for me to spot.

查看更多
贪生不怕死
3楼-- · 2020-04-03 16:36

If more than one class shares a same name this kind of error will come

查看更多
混吃等死
4楼-- · 2020-04-03 16:39

I dont really understand why this would be a problem so maybe someone could clarify but for me the problem was that I had imported another class which had declared an instance variable with the same name as one in the current class.

When I changed the name of the ivar in the imported class's implementation the error disappeared.

Hope this helps!

查看更多
家丑人穷心不美
5楼-- · 2020-04-03 16:41

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 Phases under the Compiled Sources grouping.

查看更多
欢心
6楼-- · 2020-04-03 16:46

Not sure, but a silly question - did you do a clean after clearing the old code? Sometimes that stuff hangs around.

查看更多
霸刀☆藐视天下
7楼-- · 2020-04-03 16:46

This may happen also if you have constant definitions with the same name in two different classes. In my case it was a boolean flag like these:

Class A:

#import "MyATableViewController.h"

@implementation MyATableViewController

@synthesize someVariable;

BOOL MY_FLAG = YES;
...

Class B:

#import "MyBTableViewController.h"

@implementation MyBTableViewController

@synthesize someVariable;

BOOL MY_FLAG = YES;
...

I just had to change the constant definition on the second class to:

... BOOL MY_B_FLAG = YES; ...
查看更多
登录 后发表回答