2011-08-02 67 views
10

我試圖用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 

回答

17

你也可以得到這個錯誤,你不小心包含了實現文件而不是頭文件。例如#進口「MyClass.m」代替#進口「MyClass.h」

9

就是這個原因ld: duplicate symbol _addScore

在你的項目,你有_addScore文件超過一次。檢查你的項目層次。

+0

我沒有任何與下劃線,究竟是什麼意思?下面是我無法導入的.m文件的代碼:編輯:由於註釋中沒有換行符,我還會在問題底部發布代碼。 – ObjectiveProgrammer

+0

'#import「Preferences.h」 @implementation Preferences int addScores; - (IBAction)addScoresToggled { NSLog(@「addScores was toggle。「); } - (ID)initWithWindow:(NSWindow *)窗口 { 自我= [超級initWithWindow:窗口]; 如果(個體){ } 返回自我; } - (空隙)的dealloc { [超級的dealloc];} - (無效)windowDidLoad { [超級windowDidLoad]; } @end ' – ObjectiveProgrammer

+1

可能晚了,但「int addScore」處於靜態範圍。所以,如果它包含在其他地方(或者在項目中多次包含文件),則最終會出現重複。 – GtotheB

0

我最近遇到這個錯誤。你是從兩個不同的文件導入相同的.h文件嗎?這對我造成了這個錯誤。

+0

本身不應該是個問題,聽起來更像是你包含的頭文件有問題(例如在頭文件中實例化變量) – drfrogsplat

0

如果您希望變量addScore是在多個文件中accessable,你需要在一個.m文件將其定義爲:

int addScore; 

,並在相關的.h文件聲明它:

extern int addScore; 

如果離開了在聲明中「外部」關鍵字,則編譯器看到,作爲addScore的每一個重新定義文件中的.h進口/包括進去。這會導致你看到的錯誤。

3

在收到完全相同的錯誤後,我注意到我以某種方式在我的項目中得到了兩個同名的.h文件。刪除項目文件夾中的副本(不僅僅是刪除參考)解決了我的問題。

+0

類似的事情。項目中有兩個.h文件參考。所以我刪除了一個引用。 – utsabiem

+0

得到同樣的錯誤。搜索最後導入的文件後發現重複的項目。 –

0

運行具有相同應用程序標識符的兩個項目後,我遇到了同樣的問題。

移除(使用您的帳戶名稱替換<yourlogin>)後:

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

它開始在模擬器中運行,但仍無法在設備上,所以我關閉了所有打開的項目,創造了一個新的,複製文件在那裏,最後它的工作!

0

我在使用RestKit時遇到了同樣的錯誤。我選擇了RestKit目標並清理/構建它。然後我選擇了我的主要目標(我的應用程序)並清理/構建它。爲我修復它。

0

我滿足這種類型的錯誤,當我存檔的Xcode 4.3和4.4, 下一個項目,並終於我結束了該錯誤與來自標準(64分之32位Intel)切換到64 bitIntel

2

我剛纔遇到這個問題,因爲我有意外地導入了.m文件而不是.h文件。

對於任何試圖回答此問題的人:如果問題突然出現,請仔細考慮您最近添加了哪些#import行(或者更好,請在git中運行grep!)。

0

我有一個不同的原因:使用Xcode 4.4時,部署目標設置爲10.4時,最小值爲10.6。這解決了我。

1

select demo.xcodeproj,顯示包內容,刪除名爲project.xcworkspace

0

文件,並在F xcuserdata我就遇到了這個錯誤,當我不小心點擊產品 - >測試,而不是產品 - >運行。我通過點擊產品 - >清理來清理項目,錯誤消失了。

0

複製或模糊頁眉或實現文件

當有到要導入的文件的多個潛在路徑可能發生這種情況。 例如,如果您導入MyClass.h,但也有MyClass.h兩個實例在您的項目

0

我的解決方案:

我已導入在我的項目的一些的.h和.m文件。但沒有用過我的任何課程。 所以我刪除了發現者。這導致了上述錯誤。

所以我不得不去項目設置/構建階段=>然後也刪除這些文件引用。他們是紅色的。因爲他們已經從發現者中刪除而不是從Xcode

相關問題