Commandline app throws xcode into an endless loop


#1

Hello,

I just started in chapter 2 where you need to start the commandline tool with the foundation import. But when i try to run the code it gives me 3 errors with LLVM compiler 2.0

/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFContext.h:60:23: error: expected function body after function declarator [3]
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/ApplicationServices.framework/Frameworks/HIServices.framework/Headers/AXUIElement.h:65:74: error: unknown type name 'CGCharCode' [3]
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/ApplicationServices.framework/Frameworks/HIServices.framework/Headers/AXUIElement.h:65:94: error: unknown type name 'CGKeyCode' [3]

Setting the compiler to anything other then the LLVM 2.0 send xcode into a loop and i have to kill it.

My code looks like this. The file is called main.h


#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSMutableArray *items = [[NSMutableArray alloc] init];
    
    [items addObject:@"One"];
    [items addObject:@"Two"];
    [items addObject:@"Three"];
    [items insertObject:@"Zero" atIndex:0];
    
    for(int i = 0; i < [items count]; i++)
    {
        NSLog(@"%@", [items objectAtIndex:i]);
    }

    [pool drain];
    return 0;
}

I am also using XCode4.


#2

The file should be named main.m - implementations of functions/methods don’t go in header files, and the .m indicates that the code is Objective-C and not just C.


#3

Apolagies, i meant to write .m. Makes a world of difference I know !

The problem has been resolved however. Uninstalled xcode and emptied the developer directory. Redownloaded XCode 3 and got the lastest XCode 4 and installed them into their own respective directories and no more compile errors :slight_smile: