10
votes

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

5
Where did you declare _selected?MJN
Did you accidently declare a .m file rather than a .h?Henry F
have you tried to do #import "headerfile.h" when there is not an actual headerfile.h?user2277872

5 Answers

15
votes

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.

4
votes

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;
3
votes

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.

0
votes

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

0
votes

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.