3

iam beginner in Objective-C, i tried to compile small Hello world program to start,iam using windows vista and the shell console, my code is:

 #import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    // insert code here...
    NSLog(@"Hello, World!");
    [pool drain];
    return 0;
}

the shell result show me the following error:

Foundation.h: no such file found

my command for compiling is:

gcc -o hello hello.m

i will appreciate any help, thanx in advance :)

4

2 回答 2

4

Foundation 以及 NSAutoreleasePool 和 NSLog 是苹果专有的 ObjC 框架 cocoa 和 cocoa-touch 的一部分。虽然您可以使用 Objective-C,但 Foundation 和所有 Foundation 类和函数仅在 Mac OS X 和 iOS 上可用。

如果您想继续使用 ObjC 和类,您有三个选择

  1. 自己写所有东西(这会很难,因为你说你是初学者,所以你不会有关于课程的知识)
  2. 使用类似 GNUStep 的东西试图克隆 Foundation
  3. 切换到 Mac OS X
于 2011-02-03T21:35:07.503 回答
3

尝试将其写入命令行。我有同样的问题,它对我有用。

gcc -I"c:/GNUstep/GNUstep/System/Library/Headers" -L "c:/GNUstep/GNUstep/System/Library/Libraries" -o hello hello.m -lobjc -lgnustep-base -fconstant-string-class=NSConstantString
于 2012-02-02T13:54:58.467 回答