Linker Command Failed with exit code 1: duplicate

2019-06-15 14:17发布

问题:

ld: duplicate symbol _velocityX in \
/Users/Student/Library/Developer/Xcode/DerivedData/finalproject-ffzevekmatxvhrgisgeleoijyllr/Build/Intermediates/finalproject.build/Debug-iphonesimulator/finalproject.build/Objects-normal/i386/Level2ViewController.o \
and \
/Users/Student/Library/Developer/Xcode/DerivedData/finalproject-ffzevekmatxvhrgisgeleoijyllr/Build/Intermediates/finalproject.build/Debug-iphonesimulator/finalproject.build/Objects-normal/i386/Level1ViewController.o \
for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

UPDATE: added \ + newlines for readability

I have no clue what is wrong with my project, can anyone help?

回答1:

I had same problem. But it was my fault. :). You might have writen a #import file.m instead of #import file.h. So Compiles Resource will duplicate symbol file.o. - That's it! ^^ To see it, You remove that error file, build --> Show error row --> then recopy it.



回答2:

I had this same error, it was because I defined a constant with the same name in two separate .m files. Once I changed the name in one of them, it compiled.

For example in my ViewController.m I had:

#import "ViewController.h"
const int IPHONE4 = 480;

and in my Menu.m:

#import "Menu.h"
const int IPHONE4 = 480;

I changed my Menu.m to:

#import "Menu.h"
const int IPHONE4H = 480;


回答3:

You probably have double _velocityX in a header file included by both Level1ViewController.c and Level2ViewController.c, when the header should have extern double _velocityX, and exactly one of the .c files should have double _velocityX. (Assuming the type of _velocityX is double, which seemed reasonable, and also assuming this is either C or C++ and not Fortran or something).



回答4:

I ran into this same error while trying to integrate a few frameworks into my app.

First I was using Sparrow - a graphics library, and by default I had a main.m file, things were fine until I tried to integrate Parse which also depended on the FacebookSDK. Within the FacebookSDK folders there is a Sample app called Scrumptious with a main.m as well which was the source of my problems. I removed the sample apps directory and everything built fine.