2010-11-05 48 views
0

我試圖編譯XCode中一個微不足道的命令行工具:鏈接錯誤,同時訪問NSSpeechSynthesizer

#import <Cocoa/Cocoa.h> 

int main (int argc, const char * argv[]) { 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 

    //NSSpeechSynthesizer *speeker = [[NSSpeechSynthesizer alloc] initWithVoice: nil]; 

    NSLog(@"%@", [NSSpeechSynthesizer availableVoices]); 

    NSLog(@"Hello, World!"); 
    [pool drain]; 
    return 0; 
} 

甚至想到我進口Cocoa.h,我得到一個鏈接錯誤:

Undefined symbols:
"_OBJC_CLASS_$_NSSpeechSynthesizer", referenced from: objc-class-ref-to-NSSpeechSynthesizer in byc.o ld: symbol(s) not found collect2: ld returned 1 exit status

任何人都知道發生了什麼?

回答

1

您導入了標頭,因此編譯工作正常,但鏈接失敗,因爲您沒有鏈接到提供NSSpeechSynthesizer的框架。您需要鏈接到Application Kit框架(除Foundation之外)或Cocoa傘形框架(而不是Foundation)。

無論您選擇哪種架構,它在您的項目組樹添加到您的鏈接的框架組(該組通過右鍵單擊並選擇「添加現有框架」),並確保你也把它添加到你的目標。

+0

Peter,對於這個愚蠢的問題感到抱歉,但我應該在哪裏添加此選項?我試圖打開項目設置,但無法在鏈接器部分找到合適的位置。 O :-) – cfischer 2010-11-05 18:39:40

+0

沒關係,我找到了。這比我想象的要容易:只需將可可框架添加到「外部框架和庫」組中即可。 – cfischer 2010-11-05 18:45:10

+0

順便說一句,以下是如何做到這一點,以防其他人需要此信息:http://wiki.remobjects.com/wiki/Linking_Custom_Frameworks_from_your_Xcode_Projects – cfischer 2010-11-05 18:46:08