5

I am beginner in Iphone programming. I am trying to compile (ubuntu).

#import <Foundation/Foundation.h>

int main (void)
 {
  NSLog (@"Executing");
  return 0;
 }

I compiled it but getting following error

   subhash@subhash-Lenovo-G570:~/grit/iphone/mac$ gcc -lgnustep-base -lpthread -lob
  jc -lm -I/usr/local/include/GNUstep -I/usr/include/GNUstep -fconstant-string-cla
  ss=NSConstantString hello.m -o hello
  In file included from /usr/include/GNUstep/Foundation/NSClassDescription.h:30:0,
                  from /usr/include/GNUstep/Foundation/Foundation.h:50, 
                  from hello.m:1:
  /usr/include/GNUstep/Foundation/NSException.h:42:2: error: #error The current se
  tting for native-objc-exceptions does not match that of gnustep-base ... please 
  correct this.

i followed the http://ubuntuforums.org/showthread.php?p=5593608 as a reference.

I commented #error directive of NSException.h and problem is solved. Now i am getting new error.

/tmp/ccQlI9wJ.o: In function `main':
        hello.m:(.text+0x11): undefined reference to `NSLog'
        /tmp/ccQlI9wJ.o: In function `__objc_gnu_init':
        hello.m:(.text+0x2a): undefined reference to `__objc_exec_class'
        /tmp/ccQlI9wJ.o:(.data+0x40): undefined reference to `__objc_class_name_NSConsta
        ntString'
        collect2: ld returned 1 exit status
5
  • I had to comment out that error in NSException.h, nothing else worked. Commented Jul 6, 2012 at 7:52
  • how can i correctly compile it. Commented Jul 6, 2012 at 8:03
  • that's what I just wrote. Comment out the #error directive in the header file. Commented Jul 6, 2012 at 8:14
  • thanks, that problem solved but i am getting new errors. Commented Jul 6, 2012 at 8:49
  • I think it's a much better idea to avoid all packages and install GNUstep directly from trunk. And use clang. Or use this one lists.gnu.org/archive/html/discuss-gnustep/2012-10/… Commented Feb 4, 2013 at 23:27

2 Answers 2

3

in Compile Objective-C Programs Using gcc there is the following

Also note that if you did not include -D_NATIVE_OBJC_EXCEPTIONS, you may run into the following error:

/usr/include/GNUstep/Foundation/NSException.h:42:2: error: #error The
current setting for native-objc-exceptions does not match that of
gnustep-base ... please correct this.

I has the same error as the original poster did, and passing the -D_NATIVE_OBJC_EXCEPTIONS flag fixed the problem for me. I was trying to do something pretty non-standard, so it might not work for everyone.

Note that shalki's answer may also fix the issue. In case the link referenced there vanishes, the blog post in question, Compile Objective-C Programs on Linux is in Chinese or Japanese or something like that, so I don't know exactly what it is saying, but I think the upshot is to pass

`gnustep-config --objc-flags`

as an argument to gcc. The post has

gcc `gnustep-config --objc-flags` hello.m -o hello -I /usr/include/GNUstep/ -L /usr/lib/GNUstep/ -lgnustep-base

at the end. Now, on my machine, gnustep-config --objc-flags expands to

-MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -D_REENTRANT -fPIC -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -O2 -fno-strict-aliasing -fexceptions -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -fgnu-runtime -fconstant-string-class=NSConstantString -I. -I/home/faheem/GNUstep/Library/Headers -I/usr/local/include/GNUstep -I/usr/include/GNUstep

Yowza. Notice that this list of flags does contain-D_NATIVE_OBJC_EXCEPTIONS, along with lots of other stuff. For the record, my machine is running Debian squeeze. This might be a Debian/Ubuntu specific problem. I'm not sure.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, this did the trick for me. I simply expanded gnustep-config --objc-flags and used all parameters except D_NATIVE_OBJC_EXCEPTIONS. Good catch!
0

Better write a GNUmakefile.

http://www.gnustep.it/nicola/Tutorials/WritingMakefiles/index.html

And better stop using gcc and switch to clang.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.