【发布时间】:2012-04-01 08:39:28
【问题描述】:
在尝试使用 clang 编译时,我在使用以下 Objective-C 代码时遇到以下错误。
Obj-C 代码:
// first program example
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
@autoreleasepool {
NSLog (@"Programming is fun!");
}
return 0;
}
错误信息:
main.m:6:5: error: unexpected '@' in program
@autoreleasepool {
^
main.m:7:38: error: extraneous ')' before ';'
NSLog (@"Programming is fun!");
^
main.m:7:16: warning: expression result unused [-Wunused-value]
NSLog (@"Programming is fun!");
^~~~~~~~~~~~~~~~~~~~~~
main.m:9:5: error: expected identifier or '('
return 0;
^
main.m:10:1: error: expected external declaration
}
^
1 warning and 4 errors generated.
我可以在 XCode 中正确编译。
Clang 信息: Apple clang 2.1 版 (tags/Apple/clang-163.7.1) (基于 LLVM 3.0svn) 目标:x86_64-apple-darwin11.3.0 线程模型:posix
【问题讨论】:
-
你用的是什么版本的clang?
@autoreleasepool{}是新的,Clang 正在快速发展。
标签: objective-c clang