Trying Objective-C on Linux

iOS (and Android apps) development is hot, nowadays. If you are going to build native iOS apps, of course you have to know the Objective-C programming language.

One possible questions arises:

Can I learn Objective-C on Linux? I don’t have any Macs. They are damn expensive.

I believe the answer is a symphatic YES. Meet GNUstep, the open source implementation of Cocoa. Native iOS apps use Cocoa, and it is very likely that it is more advanced thatn GNUstep, but nevertheless GNUstep is fine for learning the language fundamentals.

Obviously the next part is Linux flavoured (I’m using 64 bit ArchLinux, to be specific). If you are using another OSes, please check this page, so you can set the development environment up properly.

  1. Install the Objcective-C compiler: sudo pacman -S gcc-objc-multilib
  2. Install the GNUstep packages: sudo pacman -S gnustep-base gnustep-back gnustep-gui gnustep-make

So let’s try to build this “Hello world” program (I took it from here):

#import <Foundation/Foundation.h>

@interface HelloWorld : NSObject
-(void) hello;

@implementation HelloWorld
-(void) hello {
    NSLog(@"Hello world!");

int main(void){
   HelloWorld *hw = [[HelloWorld alloc] init];
   [hw hello];
   [hw release];

And this is how I compiled it:

gcc hello.m -o hello -I /usr/include/GNUstep/ -L /usr/lib/GNUstep/ -lobjc -lgnustep-base -fconstant-string-class=NSConstantString

And the output is:
2012-02-15 00:05:04.314 hello[4243] Hello world!

Not bad, eh?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s