Setup Objective-C dev env in Ubuntu 18.04 LTS

Posted by Danni on May 15, 2020

It is perfectly fine to run Objective-C code in Ubuntu environment since Clang is available for installation as a package for most of the Linux distributions. So if you do not have a MBP like I do, and wanna get a sense of how OC code works(but not to develop an iOS application, unfortunately, since the iOS/OS X dev stack inclduing the framework, APIs and toolings are not available for Linux), this is the starter guide for you:

1. Install GNU Objective-C Compiler & CNU-step Dev Libraries

Objectiv-C on Linux requires the GNUstep package and the Clang compiler(Or the GCC);

sudo apt-get install gobjc gnustep gnustep-devel

2. Create the first Hello, World OC program

touch hello.m  # create the file hello with .m extension
nano hello.m # Edit the file

Use Ctrl + Shift + V the paste following code; Ctrl + S to save and Ctrl + X to exit;

// 'Hello World' Program in Objective-C
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSLog (@"Hello, World!");
    [pool drain];
    return 0;

Now compile the code in terminal:

gcc $(gnustep-config --objc-flags) -o hello hello.m $(gnustep-config --base-libs)

Now, if you run ls or l again, we will see the compiled program in the same file path:

~$ l
hello*  hello.d  hello.m

Now run the program. We will have the output in the format of date time exc_num file output; Super easy and simple ;)

~$ ./hello
2020-05-15 14:12:37.659 hello[18392:18392] Hello, World!