2012-11-19 94 views
5

系統:簡單的Hello World在Objective-C鏗鏘和GNUstep的不編譯

64bit Ubuntu Lucid 
GNUStep 
clang/LLVM 

test.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時,它編譯得很好,但鏗鏘沒有。

回答

10

在一個新的安裝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 

(最後的符號鏈接需要正確定位objc.h頭)

然後我編譯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 

[email protected]:~/Desktop$ ./test 
2012-11-20 11:02:08.184 test[11856] Hello world! 

*編輯

在新10.04-64bit這允許編譯就好了:

$ 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 
+0

-______________-現在給了我一個錯誤說'在/ usr /斌/勞工處:找不到-lobjc'。我已經安裝了所有列出的項目... – texasbruce

+0

我已經更新了答案,請參閱我的編輯。 –

+1

'/ usr/bin/ld:/tmp/test-2JGYua.o:對符號'__objc_exec_class'的未定義引用 /usr/bin/ld:note:'__objc_exec_class'在DSO中定義/usr/lib64/libobjc.so .2嘗試將其添加到鏈接器命令行中 /usr/lib64/libobjc.so.2:無法讀取符號:無效操作 clang:error:鏈接器命令失敗,退出代碼1(使用-v查看調用) ' – texasbruce