Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCristian Malita
4,103 PointsLinker error?
I'm getting the following error when I'm trying to build the project:
duplicate symbol _DiaryEntryMood in:
/Users/cristianmalita/Library/Developer/Xcode/DerivedData/Diary-aosjsfqbxxmkfgcbspiawmuevdtj/Build/Intermediates/Diary.build/Debug-iphonesimulator/Diary.build/Objects-normal/x86_64/DiaryEntry.o
/Users/cristianmalita/Library/Developer/Xcode/DerivedData/Diary-aosjsfqbxxmkfgcbspiawmuevdtj/Build/Intermediates/Diary.build/Debug-iphonesimulator/Diary.build/Objects-normal/x86_64/NewEntryViewController.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It seems that if I remove the NS_ENUM from the DiaryEntry.h file, it works. I've pretty much tried everything, including starting a new project and writing it all over again from scratch. If I download the project files, they work fine, but I want to know what I'm doing wrong.
3 Answers
Cristian Malita
4,103 PointsOk, I have managed to solve this, I'm answering my own question in case someone else encounters the same problem. The problem seems to be that the "No common blocks" in the "Apple LLVM 6.1 - Code Generation" section in the Build settings pane is set to Yes, in the latest version of Xcode.
There are two ways I could solve this. One was to navigate to Diary in project navigator, select Build Settings, scroll down to Apple LLVM 6.1 Code Generation and change the No common blocks
option to No
. The second (and probably the better) way, was to just use the extern keyword in front of NS_ENUM
in DiaryEntry.h (or THDiaryEntry.h, depending on how you have it set up).
Nilson Nascimento
3,806 PointsThank you for posting the solution Cristian.
Florian Thompson
Courses Plus Student 18,609 PointsYou sir deserve a hell lot of cookies. Thank you very much!
Eduardo MejΓa
36,816 PointsEduardo MejΓa
36,816 PointsYou are the man! Thanks Cristian. I had the same problem. I wrote the extern keyword in front of NS_ENUM and it worked. But why do we have to write the extern keyword in the latest version of Xcode?
Cristian Malita
4,103 PointsCristian Malita
4,103 PointsAccording to Apple, this is what the
No common blocks
option does:In C, allocate even uninitialized global variables in the data section of the object file, rather than generating them as common blocks. This has the effect that if the same variable is declared (without extern ) in two different compilations, you will get an error when you link them. The only reason this might be useful is if you wish to verify that the program will work on other systems which always work this way.
Basically, the
No common blocks
option was disabled in previous versions of Xcode, so that's why Ash didn't get any error in the video. Having the option enabled or disabled won't make any difference for this project, but if you have it enabled (which it is by default in the latest version of Xcode) you have to use theextern
keyword for it to work. I think Ash should update the teacher notes and perhaps provide a better explanation.