user2768121
user2768121

Reputation: 165

1 duplicate symbol for architecture i386

I am facing a critical problem here, Xcode throws strange exception while building it's "

duplicate symbol _selected in: /Users/mhgaber/Library/Developer/Xcode/DerivedData/اProject-Name-aopcbghvorqhdwbyudzqsyhtekcu/Build/Intermediates/Project-Name.build/Debug-iphonesimulator/Project-Name.build/Objects-normal/i386/ClassX.o /Users/mhgaber/Library/Developer/Xcode/DerivedData/Project-Name-aopcbghvorqhdwbyudzqsyhtekcu/Build/Intermediates/Project-Name.build/Debug-iphonesimulator/Project-Name.build/Objects-normal/i386/ClassY.o ld: 1 duplicate symbol for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I searched a lot but I didn't find anything help me please

Upvotes: 10

Views: 10656

Answers (5)

Patrick Walter
Patrick Walter

Reputation: 73

I had the same issue. I was including a .h file with a number of const strings, methods and a struct. When I changed them all to static except the only mutable variable I wanted, it compiled just fine.

Upvotes: 0

static0886
static0886

Reputation: 784

I was having the same problem and @dtrotzjr 's answer gave me a hint as to what could be causing it.

In my case I had a plain C void function in my framework (which xcode was complaining about as a duplicate symbol) and i needed to declare it as static void

Upvotes: 0

devios1
devios1

Reputation: 37985

In my case, I was declaring a const in a header file, which worked fine when building and running on the device (iPhone 5), however when attempting to simulate a 4S, all of a sudden I had some 300 "duplicate symbols".

It turns out I needed to also mark the const as static and the issue went away. Presumably it was trying to redefine the constant every time the header was referenced. The compiler isn't smart enough to just make constants static? Didn't think that would be necessary, but I guess it is.

const CGFloat kTitleAnimateDistance = 50.f;

Needed to be:

const static CGFloat kTitleAnimateDistance = 50.f;

Upvotes: 4

Ali Raza
Ali Raza

Reputation: 613

Some time you accidentally importing the .m file instead of the .h due to which this error comes. Please check and If this is not the reason, then perform the following steps

1- Check Build phases in Target settings.

2- Go to compile source section.

3- Check if any file exists twice or once.

4- If file exist twice delete one.

5- Build again.

Upvotes: 3

dtrotzjr
dtrotzjr

Reputation: 945

Look at both the files for ClassX and ClassY - What targets are they included in? Basically the _selected method is duplicated in both of them. I am going to guess this is a plain C method that happens to be named the same in both files. Try renaming _selected in one of the files.

Upvotes: 15

Related Questions