Objective-c学习一 使用gcc对Objective-c进行编译

win7环境下,通过一系列安装等得到MINGW32下的Shell,

这个Shell等同于linux下的终端,可以用ls-a,等命令测试下是否工作正常。

如果一个.m文件存在D:/App/helloworld.m

#import <Foundation/Foundation.h>

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

{

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

NSLog (@"Hello World!");

[pool drain];

return 0;

}

在Shell中

cd D:

cd App:

gcc -o helloworld helloworld.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString

上面这行语句可以在这个网页看到http://www.jaysonjc.com/programming/objective-c-programming-in-windows-gnustep-projectcenter.html

上面这个命令可以写成bat执行,就不用每次都用DOS窗口写,比较省事了。

Shell中执行gcc -o ......后

执行 ./helloworld

得到输出结果 HelloWorld!