Search code examples
iphoneobjective-cosx-snow-leopard

Can't build objective-c project when including Foundation


Sorry in advance if this has been answered, I've searched repeatedly here and the in the apple docs, but haven't found out what is causing this problem. I have a iOS app that is driven by a 'layout' file that contains references to the content. I wanted to create a command line tool to optimize the content and modify the layout file if need. For example, by tiling an image and replacing it in the layout by the tiles.

I thought to create my first ever OSX tool and used the newest Xcode to create a CoreFoundation project, which gives me a main.c like this:

#include <CoreFoundation/CoreFoundation.h>

int main (int argc, const char * argv[])
{
    CFShow(CFSTR("Hello, World!\n"));
    return 0;
}

which builds fine. I thought to use some of the NS* classes to start working with the command line args, but as soon as I included the Foundation framework and added this line:

#include <Foundation/Foundation.h>

I started to get tons of build errors. I think I'm missing something basic, here, but I can't see it! Did I choose the wrong template? Is there a better one? Or, what's the problem with using Foundation here?


Solution

  • You need to set the file language to Objective C for it to compile. Either that or rename main.c in main.m