参照《iOS应用安全攻防》P150上讲的方法,打算编译以下文件
编译步骤:
export PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
$PLATFORM/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 -o test main.m -isysroot $PLATFORM/Developer/SDKs/iPhoneOS6.1.sdk -framework Foundation -lobjc
出现以下错误:
怎么解决?
我的环境是Mac OS 10.8.5 Xcode4.6.3
碰到问题要善用google,凡是这种能报出具体错误的问题,以具体的错误为关键词搜一下,一般都可以搜到答案,比如搜“gcc @autoreleasepool”,可以得到如下2个链接,解决你的问题http://stackoverflow.com/questions/10468901/autoreleasepool-was-not-declared-in-this-scope-error,http://stackoverflow.com/questions/6381764/xcode-4-2-compiler-error。
简单地说,就是@autoreleasepool是LLVM 3.0以后加入的特性,这种写法gcc不支持,如果非要用gcc编译,那就写成
NSAutoreleasePool *pool = [NSAutoreleasePool alloc] init];
[pool drain];
的形式。
现在苹果已经弃用gcc编译器,改用clang编译器了,建议你紧跟潮流换成clang,编译你的代码,用下面这条命令应该就可以“clang -arch armv7 -arch armv7s -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -framework Foundation -o test main.m”