XCode 4.2 Compiler Error

纵饮孤独 提交于 2019-12-11 03:59:06

问题


When I create a new Project with XCode 4.2 (a Single View iOS App, for instance) the main.m-File in the "Supporting Files"-Folder looks like:

#import <UIKit/UIKit.h>
#import "iiiAppDelegate.h"

int main(int argc, char *argv[])
{
    int retVal = 0;
    @autoreleasepool {
    retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([iiiAppDelegate class]));
    }

    return retVal;
}

The Compiler Setting (in Build Settings) is the Apple 3.0 LLVM. When I change it to GCC 4.2 or GCC4.2 LLVM it shown errors with the main.m.

There is no @autoreleasepool...

Which Setting in my Xcode can cause such troubles? Why is the standard compiler for new projects the Apple 3.0LLVM instead of the system default compiler (GCC4.2)??


回答1:


To answer your first question:

Which Setting in my Xcode can cause such troubles?

The compiler itself is the setting. Change it to LLVM 3.0 and no more troubles

To answer your second question:

Why is the standard compiler for new projects the Apple 3.0LLVM instead of the system default compiler (GCC4.2)??

LLVM 3.0 IS the system default compiler for Xcode 4.2.

I think what you are actually asking is how to fix the error when not using LLVM 3.0. To do that, you would want to replace @autoreleasepool with NSAutoreleasePool like so:

int main(int argc, char *argv[]) {
    int retVal = 0;

    // @autoreleasepool {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([iiiAppDelegate class]));

    [pool drain];
    // }

    return retVal;
}



回答2:


@autoreleasepool is a new feature added in LLVM 3.0. It just cannot work using the other compilers you tried.



来源:https://stackoverflow.com/questions/6381764/xcode-4-2-compiler-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!