开发者

Command /Developer/usr/bin/clang failed with exit code 1

I was trying to make a simple Mac Objective-C appl开发者_如何学Pythonication 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


You can also get this error of you accidentally include the implementation file rather than the header file. e.g. #import "MyClass.m" instead of #import "MyClass.h"


This is the reason ld: duplicate symbol _addScore

In your project you have _addScore file more than one time. check your project hierarchy.


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.


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!).


select demo.xcodeproj,show the package content,delete the file named project.xcworkspace and the f xcuserdata


I recently came across this error. Are you importing the same .h file from two different files? This caused this error for me.


If you want the variable addScore to be accessable in multiple files, you need to define it in one .m file as:

int addScore;

and declare it in the associated .h file as:

extern int addScore;

If left out the "extern" keyword in the declaration, then the compiler sees that as a redefinition of addScore in every file the .h is imported/included into. That would lead to the error you are seeing.


I had the same problem after running two projects with the same application identifiers.

After removing (replace <yourlogin> with your account name):

project.xcworkspace/xcuserdata/<yourlogin>.xcuserdatad/UserInterfaceState.xcuserstate

it's started running under simulator but still not on the device, so I closed all opened projects, created a new one and copied files there, and finally it worked!


I was facing the same error when using RestKit. I selected RestKit target and cleaned/built it. then I selected my main target (my application) and cleaned/built it. that fixed it for me.


I meet this kind of error when I archive a project under Xcode 4.3 and 4.4, and finally I ended up this error with switching from Standard(32/64-bit Intel) to 64-bitIntel


I had a different cause: using Xcode 4.4 the deployment target was set to 10.4 when the the minimum was 10.6. That solved for me.


I ran into this error when I accidentally clicked Product -> Test, instead of Product -> Run. I just cleaned the project by clicking Product -> Clean and the error was gone.


DUPLICATE or AMBIGUOUS header or implementation files

This can occur when there are multiple potential paths to the files you are importing. For example if you import MyClass.h, but there are two instances of MyClass.h in your project


my solution:

I have been imported some .h and .m files in my project. but have not used it any of my classes. so I removed those from finder. this caused the above error.

so I had to go the project setting/ build phases => then also remove those file references. they were in red color. because they have been deleted from finder not from Xcode

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜