Pages

Friday, August 13, 2010

Snow Leopard. Terminal. Compile Objective-C program

Google always helps. :)
Today it helped me to compile a standard (or GNUStep ?) Objective-C program with gcc.
Here is the code:
#include <objc/Object.h>
#include <stdio.h>
#include <stdio.h>

@interface Test : Object
{
}

- (void) sayHello;

@end;

@implementation Test


- (void) sayHello
{
printf("Hello\n");
}

@end

int main(void)
{
id t;
t = [Test new];
[t sayHello];
[t free];
return 0;
}
The command to compile is the following:
gcc -arch i386 test.m -o test -lobjc
It means that the output file ./test supports the Mach-O architecture. You can verify it as:
file ./test
The output:
./test: Mach-O executable i386

No comments:

Post a Comment