Windows的Objective-C开发环境(转)

发布日期:2012-09-06 10:15:22

  在Windows下搭建Objective C开发环境
  首先到http://www.gnustep.org/experience/Windows.html下载GNUstep MSYS System、GNUstep Core、GNUstep Devel三个文件,然后

依次安装。在“开始”菜单中“所有程序”下可以找到“GNUstep”->“shell”,就会出console窗口,可以试试一些Linux命令

(ls,cd,mkdir等)。

#import  
int main (int argc, const char *argv[]) {   
  NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];     
  NSLog(@"Hello World!");   
  [pool drain];   
  return 0;
}  

  使用文本编辑器编写上述代码,并且保存到GNUstep安装目录下的/home下,比如我把 GNUstep安装在D:\mac\下面,则你的文件应该放在D:\mac\GNUstep\msys\1.0\home里面,具体路径可以在console下面运行pwd命令查看,取名为helloworld.m。在GNUstep的console窗口命令行下,
    1、cd /home
    2、gcc -o helloworld helloworld.m -I/GNUstep/System/Library/Headers -fconstant-string-class=NSConstantString -L/GNUstep/System/Library/Libraries -lobjc -lgnustep-base
    3、运行helloworld.exe
  说明:第二步中的一些参数明说,如果熟悉Linux/Unix下C/C++编译的话,上述参数应该很熟悉,-I表示头文件查找的路径,-L表示库文件查找路径,-l表示需要链接的库文件。但是,-fconstant-string-class=NSConstantString  对于这个参数可能比较陌生,这个参数主要是指定常量字符串所使用的class。 

  自己写了一个简单的脚本,要是嫌编译源代码麻烦,可以建一个文件,比如lc.sh,然后把下面的内容复制进去:
#!/bin/sh
gcc -o $1 $2 -I/GNUstep/System/Library/Headers -fconstant-string-class=NSConstantString -L/GNUstep/System/Library/Libraries -lobjc -lgnustep-base


然后在console下面运行如下命令:chmod +x lc.sh
以后要编译程序的时候,就在命令行下面输入:./lc.sh helloworld helloworld.m
文件中的$1和$2分别表示命令行中的helloworld 和 helloworld.m
可以在GNUstep下Shell中运行 helloworld.exe
  helloworld.exe编译并运行成功的话,说明windows下Objective C开发环境就搭建好了,这样就可以开始以廉价方式的学习Objective-C。