您的位置:首页 > 移动开发 > Objective-C

ubuntu搭建object-c环境

2012-07-06 08:54 190 查看
环境: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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: