Objective C compiling with clang on Linux Foundation/Foundation.h linking: file not found
Asked Answered
B

1

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!

Beryllium answered 2/3, 2014 at 22:21 Comment(5)
In general, it's much easier to build with a GNUmakefile than to try to supply all the arguments yourself. See gnustep.it/nicola/Tutorials/WritingMakefiles.Lao
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).Lao
Apparently you are using the gcc objc runtime. Which IIRC does not support block. You should better use the libobjc2Seleta
All right, I checked the repositories and I have libojc4 installed, but I can't find libobjc2, could this be a problem?Beryllium
libobjc2 is the lib coming from gnustep: github.com/gnustep/gnustep-libobjc2Seleta
S
0

You can use gnustep-config:

clang `gnustep-config --objc-flags` `gnustep-config --objc-libs` hello.m -o hello
Seleta answered 7/3, 2014 at 10:2 Comment(5)
Thanks, I have moved something. Now I don't get the Foundation/Foundation.h error but this:Beryllium
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?Beryllium
You need the objc runtime. You should better use the GNUstep Makefile.Seleta
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?Beryllium
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.Seleta

© 2022 - 2024 — McMap. All rights reserved.