Command /Developer/usr/bin/clang failed with exit code 1
Solution 1
This is the reason ld: duplicate symbol _addScore
In your project you have _addScore file more than one time. check your project hierarchy.
Solution 2
After receiving the exact same error, I noticed that I somehow had gotten two .h files with the same name in my project. Deleting the duplicate from the project's folder (not just removing the reference) solved the issue for me.
Solution 3
I ran into this issue just now because I had accidentally imported the .m file for a class instead of the .h file.
For anyone trying this answer: If the issue has appeared suddenly, have a think about what #import
lines you added recently (or better yet, run a grep in git!).
Solution 4
select demo.xcodeproj
,show the package content,delete the file named project.xcworkspace
and the f xcuserdata
ObjectiveProgrammer
Updated on November 01, 2020Comments
-
ObjectiveProgrammer over 3 years
I was trying to make a simple Mac Objective-C application with Xcode to keep score of two players playing a simple game with up to 36 scores per player. It isn't a very practical application because of its limited features, and it's mostly for practice. I was trying to expand the application a bit with a Preferences window, which would pop up when a menu item was clicked.
I created a file to control the men item, then a nib to pop up when it's clicked. All of this worked fine, and a new window would pop up. I put sliders, text fields, etc. on the nib, and connected them to actions. All of that worked fine.
The problem came when I tried to import the files into my root controller so that I could use the user's choices in the application.
I got the following compiler error:
Command /Developer/usr/bin/clang failed with exit code 1
Along with all of this:
Ld "/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Products/Debug/SimpleScoreKeeper Mac.app/Contents/MacOS/SimpleScoreKeeper Mac" normal x86_64 cd "/Users/myusername/Dropbox/iphone app/SimpleScoreKeeper Mac" setenv MACOSX_DEPLOYMENT_TARGET 10.6 /Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Products/Debug -F/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Products/Debug -filelist "/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Intermediates/SimpleScoreKeeper Mac.build/Debug/SimpleScoreKeeper Mac.build/Objects-normal/x86_64/SimpleScoreKeeper Mac.LinkFileList" -mmacosx-version-min=10.6 -framework Cocoa -o "/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Products/Debug/SimpleScoreKeeper Mac.app/Contents/MacOS/SimpleScoreKeeper Mac"
ld: duplicate symbol _addScores in /Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Intermediates/SimpleScoreKeeper Mac.build/Debug/SimpleScoreKeeper Mac.build/Objects-normal/x86_64/Prefrences.o and /Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Intermediates/SimpleScoreKeeper Mac.build/Debug/SimpleScoreKeeper Mac.build/Objects-normal/x86_64/RootController.o for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Command /Developer/usr/bin/clang failed with exit code 1
The (possibly) related files in my project follow.
RootController.h - All the interface declarations for stuff in the MainMenu.xib window RootController.m - Where I need to import the files to MainMenu.xib - The nib owned by the RootController class Preferences.h - A file I'd want to import, but it won't work. Preferences.m - A file I'd (maybe) want to import, but it won't work. Preferences.xib - The nib owned by the Preferences class. PreferencesMenuController.h - Where I declare the clickPreferences action. (Liked to MainMenu.xib) PreferencesMenuController.m - Where I say that clickPreferences opens up Preferences nib. (Linked to MainMenu.xib)
Is there a reason why I'd be getting this error? Is there something I need to do in the class I'm importing? Please be pretty detailed, I'm new to the language somight not know how to do certain things. And if there's anything I need to clarify, let me know.
EDIT: Here's the code to the file I can't import.
#import "Preferences.h" @implementation Preferences int addScores; - (IBAction)addScoresToggled { NSLog(@"addScores was toggled."); } - (id)initWithWindow:(NSWindow *)window { self = [super initWithWindow:window]; if (self) { } return self; } - (void)dealloc { [super dealloc]; } - (void)windowDidLoad { [super windowDidLoad]; } @end
-
ObjectiveProgrammer over 12 yearsI have nothing with an underscore, what exactly does that mean? Heres the code to the .m file I can't import: Edit: Since there are no line breaks in the comments, I'm going to also post the code at the bottom of the question.
-
ObjectiveProgrammer over 12 years
#import "Preferences.h" @implementation Preferences int addScores; - (IBAction)addScoresToggled { NSLog(@"addScores was toggled."); } - (id)initWithWindow:(NSWindow *)window { self = [super initWithWindow:window]; if (self) { } return self; } - (void)dealloc { [super dealloc]; } - (void)windowDidLoad { [super windowDidLoad]; } @end
-
GtotheB over 12 yearsProbably late, but the "int addScore" is in static scope. So, if it's included elsewhere (or file included multiple times in the project), you'll end up with a duplicate.
-
drfrogsplat over 12 yearsthat in itself should not be a problem, sounds more like something wrong with the header file you were including (e.g. instantiating variables in a header file)
-
utsabiem almost 12 yearsSimilar thing. I had two .h file reference in the project. So I deleted one reference.
-
Kannan Prasad almost 12 yearsGot same error .After searching the last imported files found duplicate items .