5

我终于让 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");
}
4

3 回答 3

12

这是 -

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

如何使用 gcc 编译目标 c 程序

于 2011-02-12T04:36:53.037 回答
3

尝试以下操作:

$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.
于 2012-09-26T22:46:52.803 回答
0

这很简单,只需在-lgnustep-base和之间放一个空格-fconstant-class=NSConstantString

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

正确的路:-lgnustep-base -fconstant-class=NSConstantString

于 2012-10-09T16:35:22.340 回答