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