views:

102

answers:

3
#import <stdio.h>
#import <Foundation/Foundation.h>

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

I have a MacAir running OS X 10.6.1 with XCode version 3.2.1. When I attempt to compile the lines above I get 3951 errors. Most of them seem to be NSObjCRunntime.h file where NSString is defined. When I comment out #import <Foundation/Foundation.h> I get no errors. Is there something wrong in my setup?

Thanks

+2  A: 

It sounds like you're compiling this as C, so the Objective-C in Foundation is freaking it out. How are you compiling this? What sort of project is it? Is the file called main.c (which is a C file) or main.m (which is an Objective-C file)?

Chuck
While technically true, you can compile .c files as Objective-C by getting the files info (in Xcode) and changing the file type (in the General tab) from `sourcecode.c` to `sourcecode.c.objc`.
Dave DeLong
I never said otherwise.
Chuck
+1  A: 

You're not linking in the Foundation framework. Check out the "Like binary with libraries" phase of your target, and make sure that Foundation.framework is in there.

Dave DeLong
A: 

Make sure you link against the specified SDK and framework:

gcc -isysroot /Developer/SDKs/MacOSX10.5.sdk  -framework CoreServices -framework CoreFoundation ...

Replace as needed for your version of the SDK and your frameworks.

jeffamaphone