我試圖用Xcode製作一個簡單的Mac Objective-C應用程序,以保持兩位玩家玩一個簡單遊戲的分數,每位玩家最多可獲得36分。由於其功能有限,它不是一個非常實用的應用程序,而且主要是用於練習。我試圖用一個首選項窗口來擴展應用程序,當點擊一個菜單項時會彈出。Command/Developer/usr/bin/clang失敗,退出代碼爲1
我創建了一個文件來控制男性項目,然後點擊時彈出一個筆尖。所有這些工作都很好,並且會彈出一個新窗口。我將滑塊,文本字段等放在筆尖上,並將它們連接到動作。所有這一切都很好。
當我試圖將文件導入到根控制器,以便我可以在應用程序中使用用戶的選擇時出現問題。
我得到以下編譯器錯誤:
Command /Developer/usr/bin/clang failed with exit code 1
伴隨着這一切:
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
(可能)相關的文件在我的項目如下。
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)
有沒有理由爲什麼我會得到這個錯誤?在我正在導入的課程中,我需要做些什麼?請相當詳細,我是新來的語言somight不知道如何做某些事情。如果有什麼我需要澄清,讓我知道。編號: 這是我無法導入的文件的代碼
#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
我沒有任何與下劃線,究竟是什麼意思?下面是我無法導入的.m文件的代碼:編輯:由於註釋中沒有換行符,我還會在問題底部發布代碼。 – ObjectiveProgrammer
'#import「Preferences.h」 @implementation Preferences int addScores; - (IBAction)addScoresToggled { NSLog(@「addScores was toggle。「); } - (ID)initWithWindow:(NSWindow *)窗口 { 自我= [超級initWithWindow:窗口]; 如果(個體){ } 返回自我; } - (空隙)的dealloc { [超級的dealloc];} - (無效)windowDidLoad { [超級windowDidLoad]; } @end ' – ObjectiveProgrammer
可能晚了,但「int addScore」處於靜態範圍。所以,如果它包含在其他地方(或者在項目中多次包含文件),則最終會出現重複。 – GtotheB