【问题标题】:NSLog error: Can't find 'NXConstantString'?NSLog 错误:找不到“NXConstantString”?
【发布时间】:2011-06-25 23:16:38
【问题描述】:

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

【问题讨论】:

  • 经过更多的试验,似乎每当我的字符串前有一个 @ 时,我都会收到此错误,而不仅仅是在我使用 NSLog 时。
  • 在您的字符串之前没有@ 会使它成为纯C 字符串,这是用于NSLog 格式字符串的错误类型。

标签: objective-c cocoa gcc nslog gnustep


【解决方案1】:

它是-

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.
    

    【讨论】:

    • 添加-I/usr/include/GNUstep后这对我有用
    【解决方案3】:

    很简单,在-lgnustep-base-fconstant-class=NSConstantString之间加一个空格

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

    正确方法:-lgnustep-base -fconstant-class=NSConstantString

    【讨论】:

      猜你喜欢
      • 2010-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 2012-12-29
      • 1970-01-01
      相关资源
      最近更新 更多