环境:ubuntu 10.0.4
Ubuntu下Object-c的开发环境搭建:
1.安装gnustep和gobjc
sudo apt-get install gobjc gnustep gnustep-devel
失败报错缺少依赖关系grom.app
需要升级一下
2.Hello World
#import <Foundation/Foundation.h>
int main(int argc, const char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Hello world\n");
[pool drain];
return 0;
}
3.环境设置
hello.m:1: fatal error: Foundation/Foundation.h: 没有那个文件或目录
compilation terminated.
4.gcc `gnustep-config --objc-flags` hello.m -o hello
/tmp/ccrmAs5F.o: In function `main':
/home/shaochangqing/study/hello.m:3: undefined reference to `objc_get_class'
/home/shaochangqing/study/hello.m:3: undefined reference to `objc_msg_lookup'
/home/shaochangqing/study/hello.m:3: undefined reference to `objc_msg_lookup'
/home/shaochangqing/study/hello.m:4: undefined reference to `NSLog'
/home/shaochangqing/study/hello.m:5: undefined reference to `objc_msg_lookup'
/tmp/ccrmAs5F.o: In function `__objc_gnu_init':
/home/shaochangqing/study/hello.m:7: undefined reference to `__objc_exec_class'
/tmp/ccrmAs5F.o:(.data.rel+0x0): undefined reference to `__objc_class_name_NSAutoreleasePool'
/tmp/ccrmAs5F.o:(.data.rel+0x8): undefined reference to `__objc_class_name_NSConstantString'
collect2: ld returned 1 exit status
5.链接库
gcc `gnustep-config --objc-flags` -lgnustep-base hello.m -o hello
注意不是单引号
6.Run It
2012-05-13 13:59:05.650 hello[6374] Hello world