UBUNTU 配置OBJECT-C环境

本文详细介绍了在Ubuntu环境下搭建Objective-C开发环境的过程,并针对遇到的两个典型错误进行了深入分析和解决方案说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ubuntu下Object-c的开发环境搭建:
1.安装gnustep和gobjc

sudo apt-get install gobjc gnustep gnustep-devel

2.Hello World

 

#import <Foundation/Foundation.h>

int main(char argc, char* argv[]) {
    NSLog(@"hello world");
    return 0;
}

 

错误1:

$ gcc `gnustep-config --objc-flags`  hello.m -o hello
hello.m:3:5: warning: first argument of ‘main’ should be ‘int’ [-Wmain]
/tmp/ccx3pWOU.o: In function `main':
/home/tercel/workspace/objectc/hello.m:4: undefined reference to `NSLog'
/tmp/ccx3pWOU.o: In function `__objc_gnu_init':
/home/tercel/workspace/objectc/hello.m:6: undefined reference to `__objc_exec_class'
/tmp/ccx3pWOU.o:(.data.rel+0x0): undefined reference to `__objc_class_name_NSConstantString'
collect2: ld returned 1 exit status
tercel@tercel-pc:~/workspace/objectc$ gcc `gnustep-config --objc-flags`  -lgnustep-base hello.m -o hello
hello.m:3:5: warning: first argument of ‘main’ should be ‘int’ [-Wmain]
/tmp/ccAOmFM3.o: In function `main':
/home/tercel/workspace/objectc/hello.m:4: undefined reference to `NSLog'
/tmp/ccAOmFM3.o: In function `__objc_gnu_init':
/home/tercel/workspace/objectc/hello.m:6: undefined reference to `__objc_exec_class'
/tmp/ccAOmFM3.o:(.data.rel+0x0): undefined reference to `__objc_class_name_NSConstantString'
collect2: ld returned 1 exit status

错误2:

$ gcc `gnustep-config --objc-flags`  -lgnustep-base hello.m -o hello
hello.m:3:5: warning: first argument of ‘main’ should be ‘int’ [-Wmain]
/tmp/ccAOmFM3.o: In function `main':
/home/tercel/workspace/objectc/hello.m:4: undefined reference to `NSLog'
/tmp/ccAOmFM3.o: In function `__objc_gnu_init':
/home/tercel/workspace/objectc/hello.m:6: undefined reference to `__objc_exec_class'
/tmp/ccAOmFM3.o:(.data.rel+0x0): undefined reference to `__objc_class_name_NSConstantString'
collect2: ld returned 1 exit status

成功:

$ gcc `gnustep-config --objc-flags`  hello.m -o hello -lgnustep-base
$ ./hello 
2013-01-24 15:25:12.748 hello[15962] hello world


注意: 错误2 几乎和 成功 一样,就是 -l位置不一样,原因何在?

转载于:https://www.cnblogs.com/kloongin/archive/2013/06/06/3121486.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值