gpt4 book ai didi

objective-c - 带有 clang 和 gnustep 的 Objective-C 中的简单 Hello World 无法编译

转载 作者:太空狗 更新时间:2023-10-30 03:48:59 25 4
gpt4 key购买 nike

系统:

64bit Ubuntu Lucid
GNUStep
clang/LLVM

测试.m

#import <Foundation/Foundation.h>

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

编译命令行:

clang -fobjc-gc -I /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include -I /usr/include/GNUstep/ -I /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include-fixed/ -L /usr/lib/GNUstep/ -L /usr/lib64/ -fconstant-string-class=NSConstantString -rpath /usr/lib64 -Xlinker -lgnustep-base  test.m -o Test

错误:

/usr/bin/ld: /usr/lib64//libgnustep-base.so: undefined reference to symbol '__objc_exec_class'
/usr/bin/ld: note: '__objc_exec_class' is defined in DSO /usr/lib64/libobjc.so.2 so try adding it to the linker command line
/usr/lib64/libobjc.so.2: could not read symbols: Invalid operation
clang: error: linker command failed with exit code 1 (use -v to see invocation)

在使用 GCC 时,它编译正常,但 clang 没有。

最佳答案

在全新安装的 Ubuntu 12.10 上,我安装了以下软件包:

$ sudo apt-get install build-essential
$ sudo apt-get install clang
$ sudo apt-get install gnustep
$ sudo apt-get install gnustep-make
$ sudo apt-get install gnustep-devel
$ sudo ln -s /usr/lib/gcc/i686-linux-gnu/4.7/include/objc /usr/local/include/objc

(需要最终符号链接(symbolic link)才能正确定位 objc.h header )

然后我编译了test.m文件如下:

$ clang -o test test.m -I `gnustep-config --variable=GNUSTEP_SYSTEM_HEADERS` \
-L `gnustep-config --variable=GNUSTEP_SYSTEM_LIBRARIES` \
-lgnustep-base -fconstant-string-class=NSConstantString \
-D_NATIVE_OBJC_EXCEPTIONS \
-lobjc

tux@ubuntu:~/Desktop$ ./test
2012-11-20 11:02:08.184 test[11856] Hello world!

* 编辑

在新的 10.04-64 位上,这允许编译得很好:

$ sudo apt-get install build-essential
$ sudo apt-get install clang
$ sudo apt-get install gnustep-devel
$ sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include/objc/ /usr/local/include/objc

关于objective-c - 带有 clang 和 gnustep 的 Objective-C 中的简单 Hello World 无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13446450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com