andLinux で Objective-C

gcc で compile できるみたいなのでちょっと触ってみた。まず環境の整備。つっても root で以下の一行打てば済むんだけど。

apt-get install gobjc

で、 compile するときは以下のように。 -lobjc が重要。

gcc -Wall --pedantic -lobjc source.m

最後、ちゃんと compile できるかという test 用の code 。おなじみですね。

/*
 * objective-helloworld.m
 *  hello world via an object
 *
 *  > gcc -Wall --pedantic -lobjc helloworld.m
 *
 *  written by janus_wel<janus.wel.3@gmail.com>
 *  This source code is in public domain, and has NO WARRANTY.
 * */

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

@interface HelloWorld : Object
- (void)say;
@end

@implementation HelloWorld
- (void)say {
    printf("Hello World\n");
}
@end

int main(void) {
    id hw = [HelloWorld alloc];
    [hw say];

    return 0;
}