Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLog error: Can't find 'NXConstantString'?

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");
}
like image 632
John Howard Avatar asked Feb 12 '11 04:02

John Howard


2 Answers

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

like image 132
Mahesh Avatar answered Oct 02 '22 23:10

Mahesh


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.
like image 32
saxena jitendra Avatar answered Oct 02 '22 23:10

saxena jitendra