Geremy
Geremy

Reputation: 2445

unable to find objc.h during clang compile

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?

Upvotes: 5

Views: 4425

Answers (3)

Daniil Iaitskov
Daniil Iaitskov

Reputation: 6039

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.

Upvotes: 1

SqAR.org
SqAR.org

Reputation: 607

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

Upvotes: 0

user1282993
user1282993

Reputation:

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.

Upvotes: 2

Related Questions