6

I'm trying to compile a program in Objective C on Ubuntu, I have installed GNUstep, set all the GNUSTEP_* environment variables, and installed clang, because I read that gcc can't compile Objective-C code with blocks (Objective-C 'anonymous' functions, just to be clear: ^ { }).

What I get when I run this command: clang hello.m -o hello

Is:

hello.m:1:9: fatal error: 'Foundation/Foundation.h' file not found
#import <Foundation/Foundation.h>
        ^
1 error generated.

I tried this also: clang -L '/usr/include/GNUstep/Foundation/Foundation.h' hello.m -o hello

Where /usr/include/... is the path to the Foundation.h file on my system; but I still get the same result.

How can I link those header files automatically and compile Objective-C?

Thanks!

echristopherson
  • 6,974
  • 2
  • 21
  • 31
tonix
  • 6,671
  • 13
  • 75
  • 136
  • In general, it's much easier to build with a GNUmakefile than to try to supply all the arguments yourself. See http://www.gnustep.it/nicola/Tutorials/WritingMakefiles/. – echristopherson Mar 03 '14 at 00:37
  • Also, `-L` is used to specify a *library* *directory*, i.e. the location of a .so or .dylib file whose name you also supplied using `-l`. Perhaps you were thinking of `-I/usr/include/GNUstep`; that would tell it where the root directory for *include* files is. In no case would you supply the full path to the actual library or header file (well, it is possible to supply a path to library files, but it's rarely done). – echristopherson Mar 03 '14 at 00:39
  • Apparently you are using the gcc objc runtime. Which IIRC does not support block. You should better use the libobjc2 – mathk Mar 07 '14 at 12:14
  • All right, I checked the repositories and I have libojc4 installed, but I can't find libobjc2, could this be a problem? – tonix Mar 07 '14 at 12:37
  • libobjc2 is the lib coming from gnustep: https://github.com/gnustep/gnustep-libobjc2 – mathk Mar 07 '14 at 17:11

1 Answers1

0

You can use gnustep-config:

clang `gnustep-config --objc-flags` `gnustep-config --objc-libs` hello.m -o hello
mathk
  • 7,973
  • 6
  • 45
  • 74
  • Thanks, I have moved something. Now I don't get the Foundation/Foundation.h error but this: – tonix Mar 07 '14 at 10:57
  • Sorry, I left this: /usr/GNUstep/System/Library/Headers/Foundation/Foundation.h:31:9: fatal error: 'objc/objc.h' file not found -- As I can suppose clang doesn't find the objc/objc.h file, am I right? Apparently the file is located in this path (I used the locate objc/objc.h command): /usr/lib/gcc/x86_64-linux-gnu/4.7/include/objc/objc.h So how can I bind it to the path where clang is gonna look when I launch it? – tonix Mar 07 '14 at 11:10
  • You need the objc runtime. You should better use the GNUstep Makefile. – mathk Mar 07 '14 at 11:29
  • Yes with the GNUstep Makefile all goes great except that I cannot compile code with Blocks, and I need them, so I came up with clang which compiles blocks, but I still get this errors. How can I download the objc runtime, is it available on the Ubuntu repositories? – tonix Mar 07 '14 at 11:54
  • When you build GNUStep you have to specify the the default compiler is clang. When building GNUstep make you should have configure it with `./configure CC=clang CXX=clang++`. Rebuild and install GNUStep make and you will have it. – mathk Mar 07 '14 at 12:10