Main Menu



You are here: Home
Objective-C on Ubuntu PDF Print E-mail
Written by Josh B   
Thursday, 16 April 2009 12:46

Tags: objective-c | ubuntu

Here's a handy tip I've gleaned from the Ubuntu Forums. This will allow you to program and run basic Objective-C on Ubuntu Intrepid. Read on after the fold...

 

1) Install the GNU Objective-C compiler:

sudo apt-get install gobjc

2) Write a quick bit of test code:

// hello.m
#import <objc/Object.h>
#import <stdio.h>

@interface Number: Object
{
@public
    int number;
   
}
- (void)printNum;

@end

@implementation Number: Object

- (void)printNum
{
    printf("%d\n", number);
}

@end

int main(void)
{
    Number *myNumber = [Number new]; // equal to [[Number alloc] init]
    myNumber->number = 6;
    [myNumber printNum];
    return 0;
}

3) Compile it:

gcc -o hello hello.m -Wall -lobjc

4) Run it...!

./hello 

I'll leave it to the astute reader to figure out what it does. Smile

The main problem with seems to be that you can't (quite obviously) use the iPhone foundation libraries. But for something to knock code into quickly to see if it runs its quite handy. Its also handy to learn the basics of Objective-C when you don't have a Mac around.

 

Last Updated on Thursday, 16 April 2009 12:56
 

Comments  

 
0 #1 Saji Nediyanchath 2011-10-26 11:35 Thanks man. I was looking for a quick code to test my GNUStep installation in Ubuntu 11.10. and the command to compile it. Quote
 

Add comment


Security code
Refresh

Joomla! Template by Red Evolution - Joomla Web Design