NSLog错误:找不到'NXConstantString'?

时间:2011-02-12 04:35:12

标签: objective-c cocoa gcc nslog gnustep

我终于让GNUstep工作(在Windows上),它编译并运行正常。但是,每当我尝试使用NSLog时,都会出现以下错误:

$ 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");
}

3 个答案:

答案 0 :(得分: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

答案 1 :(得分: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.

答案 2 :(得分:0)

-lgnustep-base-fconstant-class=NSConstantString

之间添加一个空格非常简单

错误的方式:-lgnustep-base-fconstant-class=NSConstantString

正确的方式:-lgnustep-base -fconstant-class=NSConstantString