4

I have installed clang on my Raspberry Pi. How can I compile a .m file (Objective C) through the terminal?

Let's say I called it bob.m and I want the output file to be called bob and I'm already in the correct directory, what is the exact command?

  • If I use clang bob.m -o bob: clang helloWorldObjC.m -o helloWorldObjC helloWorldObjC.m:1:12: fatal error: 'Foundation/Foundation.h' file not found #import "Foundation/Foundation.h" ^ 1 error generated. – user1628 Sep 26 '12 at 13:15
5

To compile Object-C:

clang <the file name, i.e. bob.m> -o <the target name, i.e. bob>

so

clang bob.m -o bob

Foundation is part of GNUStep which will have to be installed.

sudo apt-get install gnustep

You will then need to tell clang about it.

clang `gnustep-config --objc-flags` bob.m -o bob  `gnustep-config --base-libs`
2

You need to instal the objective c run time libraries as well as OpenStep/gnuStep if you want to import foundation.h. Objective-c does not come bundled with clang.

Apparently you can get gnustep with apt-get:

sudo apt-get install gnustep

Once that is installed, you should be able to compile against foundation.h

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.