2011-02-12 67 views
4

我終於得到GNUstep的工作(在Windows),它編譯和運行良好。但是,每當我嘗試使用的NSLog,我得到以下錯誤:NSLog錯誤:找不到'NXConstantString'?

$ gcc -o hello hello.m -I /GNUstep/System/Library/Headers \ 
> -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base 
hello.m: In function 'main': 
hello.m:4:5: error: cannot find interface declaration for 'NXConstantString' 

我的源代碼:

#import <Foundation/Foundation.h> 

int main(void) { 
    NSLog(@"hello world"); 
} 
+0

-lgnustep-base-fconstant-class=NSConstantString

正道試驗,似乎我得到th每當我在我的字符串之前有一個@,而不僅僅是當我使用NSLog。 – 2011-02-12 04:37:50

+0

這是我的整個代碼。 – 2011-02-12 04:39:30

+0

在你的字符串之前沒有`@`會使它成爲一個普通的C字符串,這是'NSLog`格式字符串使用的錯誤類型。 – 2011-02-12 06:18:31

回答

11

這是 -

NSLog(@"hello world"); 

NSlog(@"hello world"); // 'l' should be upper case in NSLog 

試試這個 -

gcc -o hello hello.m -I /usr/lib/GNUstep/System/Library/Headers \ 
-L /usr/lib/GNUstep/System/Library/Libraries/ -lgnustep-base \ 
-fconstant-string-class=NSConstantString 

How to compile objective c programs using gcc

2

嘗試以下操作:

$gcc -o hello hello.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString 

-fconstant-string-class=NSConstantString 

沒有這個命令時,它考慮常量字符串對象爲一類類型NXConstantString


運行:

$./hello.m or whatever your objective-c code file name. 
0

這是非常簡單的只是把空間-lgnustep-base-fconstant-class=NSConstantString

之間的錯誤方式:一些經過-lgnustep-base -fconstant-class=NSConstantString