NSLog error: Can't find 'NXConstantString'?
Asked Answered
R

3

5

I finally got GNUstep working (on windows), and it compiles and runs fine. However, whenever I try to use NSLog, I get the following error:

$ 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'

My source code:

#import <Foundation/Foundation.h>

int main(void) {
    NSLog(@"hello world");
}
Roundhouse answered 12/2, 2011 at 4:35 Comment(2)
After some more experimenting, it seems that I get this error whenever I have a @ before my string, not just when I use NSLog.Roundhouse
Not having an @ before your string would make it a plain C string, which is the wrong type to use for NSLog's format string.Flanagan
R
12

It is -

NSLog(@"hello world");

not

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

Try this -

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

Reluct answered 12/2, 2011 at 4:36 Comment(0)
E
3

Try the following:

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

Note

-fconstant-string-class=NSConstantString

without this command it consider constant string objects as a class type NXConstantString.


To run:

$./hello.m or whatever your objective-c code file name.
Eleanor answered 26/9, 2012 at 22:46 Comment(1)
This worked for me after i added -I/usr/include/GNUstepMargrettmarguerie
K
0

it's very simple just put a space between -lgnustep-base and -fconstant-class=NSConstantString

Wrong way: -lgnustep-base-fconstant-class=NSConstantString

Right way: -lgnustep-base -fconstant-class=NSConstantString

Kunkel answered 9/10, 2012 at 16:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.