5

I'm on Ubuntu 12.

I'm trying to compile an Objective-C hello_world app using clang. This is the source:

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
 NSLog (@"hello world");
 [pool drain];
 return 0;
}

I use this commandline:

. /usr/share/GNUstep/Makefiles/GNUstep.sh
clang h.m `gnustep-config --objc-flags` -lgnustep-base -o hello

I get the following error:

clang: warning: argument unused during compilation: '--param ssp-buffer-size=4'
In file included from h.m:1:
In file included from /usr/include/GNUstep/Foundation/Foundation.h:30:
In file included from /usr/include/GNUstep/GNUstepBase/GSVersionMacros.h:193:
In file included from /usr/include/GNUstep/GNUstepBase/GSConfig.h:229:
/usr/include/GNUstep/GNUstepBase/preface.h:112:11: fatal error: 'objc/objc.h'
      file not found
 #include <objc/objc.h>
          ^
1 error generated.

The same commandline using gcc works fine.

Any ideas how to fix this missing objc.h error?

Geremy
  • 2,415
  • 1
  • 23
  • 27

3 Answers3

2

obj-c.h is part of the Objective-C runtime, have you got that installed? From my own experience GNUstep seems to be a world of hurt on most platforms, so it may simply be GNUstep's configure scripts refusing to pick it up even if it is installed, try their mailing list if you can't get a better answer here.

  • geremy@dually:~$ locate objc.h /usr/lib/gcc/x86_64-linux-gnu/4.6/include/objc/objc.h but I dont think this is the correct one. I believe I need: https://github.com/gnustep/gnustep-libobjc2 installed instead? – Geremy Jul 13 '12 at 17:24
  • 2
    /usr/lib/gcc/x86_64-linux-gnu/4.6/include/objc/objc.h is the GCC objc runtime. Try installing gnustep-libobjc2. That makefile should place the runtime in /usr/local. Then, use the parameter -lobjc with clang to use the gnustep runtime. – jtomschroeder Jul 13 '12 at 17:52
  • 1
    I think this is the same problem, and it works on me. ubuntu 12.04. http://ubuntuforums.org/showthread.php?t=1412542 – Jerry Tian Oct 19 '12 at 17:59
1

I am newbie on MacOs. Today I had to build pyobjc Cocoa python wrapper in nix and have to deal with clang. I had similar error. As any C developer first I extended CFLAGS with I/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include, but it didn't change anything. After scratching my head for quite awhile I tried to call clang manually just with -I and it was working! So -isysroot disables -I and doesn't do anything on its own. I found -iwithprefix and put it with path I used with -I and it works with -isysroot, which I cannot easily remove - it is injected somewhere inside nix derivations into CLFAGS.

Daniil Iaitskov
  • 5,525
  • 8
  • 39
  • 49
0

That header comes as part of the ObjC-Runtime. While GCC provides a runitme (although one only without the modern features like ARC), Clang/LLVM doesn't sport such a runtime. If you want to use Clang, you need to install GNUstep's ObjC runtime , which you can find here:

https://github.com/gnustep/libobjc2

For Ubuntu, there are bash scripts available at the GNUstep-wiki, which help you in the somewhat complicated GNUstep installation process:

http://wiki.gnustep.org/index.php/GNUstep_under_Ubuntu_Linux

and one more tip: you should not try to reinvent GNUstep-make by trying to use the compiler manually, like you did. Better use GNUstep-make:

http://www.gnustep.org/resources/documentation/Developer/Make/Manual/gnustep-make_1.html

SqAR.org
  • 557
  • 6
  • 15