How to compile Objective-C code with GCC ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

When I try to compile this code that I got form here([1]) with gcc:
#import <stdio.h>
#import <objc/Object.h>

@interface Hello: Object
- (void) init;
- (void) say;
@end

@implementation Hello
- (void) init {
  [super init];
}
- (void) say {
  printf("Hello, world!\n");
}
@end

int main() {
  Hello *hello = [Hello new];
  [hello say];
  [hello free];
  return 0;
}

Comand line: g++ -x objective-c++ test.mm -otest -lobjc

When code is compiled I get the following warnings:
test.mm:11:14: warning: ‘Object’ may not respond to ‘-init’ [enabled by default]
test.mm:11:14: warning: (Messages without a matching method signature
[enabled by default]
test.mm:11:14: warning: will be assumed to return ‘id’ and accept
[enabled by default]
test.mm:11:14: warning: ‘...’ as arguments.) [enabled by default]
test.mm: In function ‘int main()’:
test.mm:19:28: warning: ‘Hello’ may not respond to ‘+new’ [enabled by default]
test.mm:21:14: warning: ‘Hello’ may not respond to ‘-free’ [enabled by default]

If I try to run - I get SIGSEGV:
$> ./test
$> Segmentation fault

What I am doing wrongly?

Thanks.


[1] http://en.wikipedia.org/wiki/List_of_Hello_world_program_examples#Objective-C



-- 
Regards,
niXman
___________________________________________________
Dual-target(32 & 64-bit) MinGW compilers for 32 and 64-bit Windows:
http://sourceforge.net/projects/mingwbuilds/
___________________________________________________
Another online IDE: http://liveworkspace.org/



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux