【发布时间】:2012-03-09 09:14:19
【问题描述】:
我正在学习 Objective-C 语言。由于我没有 Mac,我在 Ubuntu 11.04 平台上编译和运行我的代码。
到目前为止,我一直在使用 gcc 进行编译。我已经安装了 GNUStep,一切正常。但后来我开始尝试一些 gcc 不允许的 Objective-C 2.0 特性,例如 @property 和 @synthesize。
所以我尝试用 Clang 编译代码,但它似乎没有正确地将我的代码与 GNUStep 库链接起来,甚至没有一个简单的 Hello world 程序。
例如,如果我编译以下代码:
#import <Foundation/Foundation.h>
int main(void) {
NSLog(@"Hello world!");
return 0;
}
编译器的输出是:
/tmp/cc-dHZIp1.o: In function `main':
test.m:(.text+0x1f): undefined reference to `NSLog'
/tmp/cc-dHZIp1.o: In function `.objc_load_function':
test.m:(.text+0x3c): undefined reference to `__objc_exec_class'
collect2: ld returned 1 exit status
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
我用来编译的命令是
clang -I /usr/include/GNUstep/ test.m -o test
使用 -I 指令包含 GNUStep 库(否则,Clang 无法找到 Foundation.h)。
我搜索了我的问题,并访问了 GNUStep 和 Clang 网页,但我还没有找到解决方案。因此,我们将不胜感激。
谢谢!
【问题讨论】:
标签: objective-c ubuntu compiler-construction linker clang