objective-c:如何使用NSApplicationMain

时间:2016-01-09 02:37:35

标签: objective-c nsapplication

这个程序有什么问题?

// main.m
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>


int main(int argc, char *argv[])
{
    return NSApplicationMain(argc, (const char **)argv);
}

我尝试编译并得到此错误:

$ clang -framework Foundation main.m
Undefined symbols for architecture x86_64:
  "_NSApplicationMain", referenced from:
      _main in main-c04948.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$

1 个答案:

答案 0 :(得分:1)

你已经与基金会联系,但不是AppKit或Cocoa。 NSApplicationMain()是AppKit的一部分。您需要将-framework Foundation替换为-framework AppKit-framework Cocoa(它们或多或少是同义词)。