日期:2014-05-17  浏览次数:20998 次

Windows 下学习 Objective-C 环境准备 Hello world

在等最新版的Mac book pro机子,不知道什么时候会出,只能先在windows下学习最基本的语法。百度 windows Objective-c ,竟然可以在windows下整个Objective c的开发环境!

安装:

GNUstep Windows Installer提供了Windows平台下的Objective-C的模拟开发环境,一共有四个软件包,其中GNUstepSystem和GNUstepCore是必装的,GNUstepDevel和CairoBackend是选装的。甭管必装选装,一次性全安上,免得以后麻烦。4个下载下来后要注意安装的次序!!

安装好  Windows->开始-> GNUstep->Shell

出现下面的界面就说明你成功了。

 

编写helloworld.m文件,用记事本,Notepad++,UltraEdit都可以,放到C:\GNUstep\home\你的用户名 这个目录下

#import <Foundation/Foundation.h>

int main (int argc, const char *argv[])
{
    NSLog (@"Hello, Objective-C!");
	
    return (0);
	
} // main

编译helloworld.m文件

有两个方法都是可以编译的

第一个方法:

在C:\GNUstep\home\你的用户名 这个目录下新建一个文件叫GNUmakefile,没有后缀

include $(GNUSTEP_MAKEFILES)/common.make 

TOOL_NAME=helloworld
helloworld_OBJC_FILES=helloworld.m

include $(GNUSTEP_MAKEFILES)/tool.make

添加环境变量 GNUSTEP_MAKEFILES, 值为 C:\GNUstep\GNUstep\System\Library\Makefiles,根据你的安装位置变化,重启电脑。

打开shell,编写make 就可以了。会在C:\GNUstep\home\你的用户名 这个目录下生成一个obj的文件夹,里面有个helloworld.exe就是编译生成的文件

打开shell ,输入./obj/helloworld.exe 就可以看到结果了

附上GNUmakefile和helloworld.m文件的下载地址:

第二个方法:

helloworld.m文件放的地方不变还是C:\GNUstep\home\你的用户名 这个目录下

接下来要写一个文件叫 helloworld.sh

#!/bin/sh

if [ $# -ne 2 ]; then
echo "Usage: $0 source output"
exit 1
fi

gcc -g -o $2 $1 \
-lobjc \
-fobjc-exceptions \
-lgnustep-base \
-I /GNUstep/System/Library/Headers/ \
-L /GNUstep/System/Library/Libraries/ \
-fconstant-string-class=NSConstantString
然后打开shell 输入 ./helloworld.sh helloworld.m helloworld.exe

成功后就会生成helloworld.exe文件,在shell里输入 ./helloworld.exe就能得到相同的结果了。

附上helloworld.sh 和helloworld.m文件的下载地址:

helloworld1
文章源地址:http://www.waitingfy.com/?p=113