Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling objective-c programs without gnustep on ubuntu

is there any way to compile objective c programs on ubuntu without the use of GNUStep? I want to use the default C standard libraries and all but with Objective-C's OOB syntax. The problem I am having now is once I have all the methods up, I need a way to call them. In Mac I would just alloc and init it but on Linux when I try to compile this, clang just gives me an error.

#include <stdio.h> // C standard IO library (for printf)
#include <stdlib.h> // C standard library
// Interface
@interface test
 -(void)sayHello :(char *)message;
@end

// Implementation
@implementation test
 -(void)sayHello :(char *)message {
  printf("%s", message);
 }

int main(int argc, char *argv[]) {
 test *test = [[test alloc] init];
 [test sayHello:"Hello world"];
}
like image 716
Naveen Mathew Avatar asked Nov 03 '22 21:11

Naveen Mathew


1 Answers

You can compile objective-c with gcc, but remember to use the -lobjc switch so the compiler knows what language you're using.

You'll also need to include the following header:

    #import <objc/Object.h>

...and extend Object from your interface. See the hello world example for objective-c here:

http://en.m.wikipedia.org/wiki/List_of_Hello_world_program_examples#O

like image 118
Simon Curd Avatar answered Nov 13 '22 08:11

Simon Curd