首先,我们要安装相应的程序:
apt-get install gcc gobjc gcc g++ gnustep libgnustep-gui-dev
然后编写一个hello.m文件:
连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];
}
然后就是编译了:
编译成.o文件:
gcc -fconstant-string-class=NSConstantString -I /usr/include/GNUstep/ -c hello.m
链接:
gcc hello.o -o hello -lgnustep-base
一些方便的设置:
在bashrc中添加一条:
alias objcc=’gcc -fconstant-string-class=NSConstantString -I /usr/include/GNUstep/ -lgnustep-base’
以上命令就简化啦:
objcc –o hello hello.m
运行:
$ ./hello
2010-08-12 01:03:23.930 hello[1642] hello world!