WindowsでObjective-C

環境準備

http://www.gnustep.org/experience/Windows.htmlから以下をダウンロードする

  • gnustep-system-0.19.2-setup.exe
  • gnustep-core-0.19.2-setup.exe
  • SystemPreferences-1.0.2-2-setup.exe
  • gorm-1.2.4-setup.exe
  • Calculator-1.0.0-2-setup.exe

ほんでもって普通にインストール。

環境準備完了!

Objective-CHello World!

hello.m

#import <stdio.h>
#import <objc/Object.h>

@interface TestClass : Object
- (void) getMessage;
@end

@implementation TestClass
- (void) getMessage {
	printf("Hello Objective-C World\n");
}
@end

int main(int argc, char *argv[]) {
	id obj = [ TestClass alloc ];
	[ obj getMessage ];

	return 0;
}
コンパイル

gcc -o hello hello.m \
-I /GNUstep/System/Library/Headers \
-L /GNUstep/System/Library/Libraries \
-lobjc \
-lgnustep-base \
-fconstant-string-class=NSConstantString \
-enable-auto-import

実行

$ ./hello.exe
Hello Objective-C World

うひょ〜できた〜!!

FoundationライブラリでのHello World

hello.m

#import <Foundation/Foundation.h>

@interface HelloWorld : NSObject
- (void) hello;
@end

@implementation HelloWorld
- (void) hello
{
    NSLog(@"Hello world!");
}
@end

int main(void)
{
    HelloWorld *hw = [[HelloWorld alloc] init];
    [hw hello];
    [hw release];
}
コンパイル

gcc -o hello hello.m \
-I /GNUstep/System/Library/Headers \
-L /GNUstep/System/Library/Libraries \
-lobjc \
-lgnustep-base \
-fconstant-string-class=NSConstantString \
-enable-auto-import

実行

$ ./hello.exe
2008-08-06 16:52:58.234 hello[3924] Hello world!

うひょひょっ!

なんか

コンパイルが少し謎めいているけど、とりあえずOK!
iPhone開発の第一歩。。。