Objective c 访问NSSpeechSynthesizer时发生链接错误

Objective c 访问NSSpeechSynthesizer时发生链接错误,objective-c,cocoa,linker,Objective C,Cocoa,Linker,我试图用XCode编译一个简单的命令行工具: #import <Cocoa/Cocoa.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; //NSSpeechSynthesizer *speeker = [[NSSpeechSynthesizer alloc] initWithVoice: nil];

我试图用XCode编译一个简单的命令行工具:

#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;
}
#导入
int main(int argc,const char*argv[]{
NSAutoreleasePool*池=[[NSAutoreleasePool alloc]init];
//NSSpeechSynthesizer*speeker=[[NSSpeechSynthesizer alloc]initWithVoice:nil];
NSLog(@“%@,[NSSpeechSynthesizer availableVoices]);
NSLog(@“你好,世界!”);
[泳池排水沟];
返回0;
}
甚至认为我正在导入Cocoa.h,我得到了一个链接错误:

未定义的符号:
“\u OBJC\u CLASS\uu$\n语音合成器”, 引用自: objc类参考至NSSPEech合成器 在byc.o ld中:未找到符号 collect2:ld返回了1个退出状态


有人知道发生了什么吗?

您导入了标题,因此编译工作正常,但链接失败,因为您没有链接到提供NSSpeechSynthesizer的框架。您需要针对应用程序工具包框架(除了Foundation)或Cocoa伞形框架(而不是Foundation)进行链接


无论您选择哪个框架,请将其添加到项目组树中的链接框架组中(通过右键单击该组并选择“添加现有框架”),并确保您也将其添加到目标中。

Peter,很抱歉这个愚蠢的问题,但是我应该在哪里添加此选项?我尝试打开项目设置,但在链接器部分找不到合适的位置。O:-)没关系,我找到了。这比我想象的要简单:只需将cocoa.framework添加到thr“External frameworks and libraries”组中。顺便说一句,下面是如何操作,以防其他人需要此信息:费尔南多:哦,对不起。我以为你在用make。我将编辑答案。