在Windows上编写Object C程序

随着iphone的流行,越来越多的程序员开始学习Object C编程,但一般来说编写Object C需要iMac计算机。这对于刚开始学习Object C编程的程序员是个问题。
本文给出了一个在 windows 平台上学习Object C编程的方法。
1.下载GNUStep
http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/
下载
gnustep-msys-system-x.x.x-setup.exe
gnustep-core-x.x.x-setup.exe
gnustep-cairo-x.x.x-setup.exe
gnustep-devel-x.x.x-setup.exe
将下载的GNUStep安装,比如C:\GNUStep
2. 下载JEdit
http://www.jedit.org/index.php?page=download
JEdit 是Freeware,可以用来编辑 .m 文件 .m 是Object C缺省后缀。 .m 相当于 .c 文件
3. 一个Object C教材
http://www.otierney.net/objective-c.html
---------------------------------------------
4. 安装后,执行msys.bat 启动 GNUStep 环境 (类Linux环境)

5. 编写示例程序
fraction.h

#import <Foundation/NSObject.h>
 
@interface Fraction: NSObject {
     int numerator;
     int denominator;
 }
 
-(void) print;
 -(void) setNumerator: (int) n;
 -(void) setDenominator: (int) d;
 -(int) numerator;
 -(int) denominator;
 @end

fraction.m

#import "fraction.h"
 #import 

@implementation Fraction
 -(void) print {
     printf( "%i/%i", numerator, denominator );
 }
 
-(void) setNumerator: (int) n {
     numerator = n;
 }
 
-(void) setDenominator: (int) d {
     denominator = d;
 }
 
-(int) denominator {
     return denominator;
 }
 
-(int) numerator {
     return numerator;
 }
 @end


main.m

#import 
#import "fraction.h"
 
int main( int argc, const char *argv[] ) {
     // create a new instance
     Fraction *frac = [[Fraction alloc] init];
 
    // set the values
     [frac setNumerator: 1];
     [frac setDenominator: 3];
 
    // print it
     printf( "The fraction is: " );
     [frac print];
     printf( "\n" );
 
    // free memory
     [frac release];
 
    return 0;
 }


6. 编写Makefile
在当前目录下创建GNUmakefile

include $(GNUSTEP_MAKEFILES)/common.make
 
TOOL_NAME = Hello
 Hello_OBJC_FILES = main.m fraction.m
 
include $(GNUSTEP_MAKEFILES)/tool.make

6. 编译程序
$ make
将创建 obj目录 运行 hello.exe
The fraction is: 1/3
这样环境就搭好了,你就可以继续学习 Object C了

最终写iphone程序一般还是要Mac OS.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值