Compiling a Program67
STR msg;
}
+ new;
- print;
- setMessage: (STR) str;
@end
@implementation HelloWorld
+ new
{
self = [super new];
[self setMessage : ""];
return self;
}
- print
{
printf("%s\n", msg);
return self;
}
- setMessage: (STR) str
{
msg = str;
return self;
}
@end
int main(int argc, char**argv) {
id msg;
msg = [HelloWorld new];
[msg setMessage: "Hello World"] ;
[msg print];
return 0;
}
You can compile and link it using the
gcc hello.m –lobjc
command. The output is
again
a.out
file that can be executed on the command line.
This is sort of a long “Hello World” program. There are much shorter Objective C “Hello
World” programs available on the Internet.