我正在尝试在Ubuntu WITHOUT GNUStep上运行一个简单的Objective-C程序,这段代码可以运行:
#import <stdio.h>
int main(int argc, char* argv[]){
printf("hi");
return 1;
}
但是,当我编译以下代码时:
#import <stdio.h>
#import <objc/Object.h>
@interface MyObject : Object
-(void) printHello;
@end
@implementation MyObject
-(void) printHello{
printf("Hello!");
}
@end
int main(int argc, char* argv[]){
MyObject* obj = [MyObject new];
[obj printHello];
return 1;
}
它编译,发出以下警告:
main.m: In function ‘main’:
main.m:19:2: warning: ‘MyObject’ may not respond to ‘+new’ [enabled by default]
MyObject* obj = [MyObject new];
^
main.m:19:2: warning: (Messages without a matching method signature [enabled by default]
main.m:19:2: warning: will be assumed to return ‘id’ and accept [enabled by default]
main.m:19:2: warning: ‘...’ as arguments.) [enabled by default]
如果我然后运行a.out,它会给我一个分段错误。
有没有办法解决这个没有GNUStep?
答案 0 :(得分:0)
没有修复,因为您的破解代码正在调用未实现的类方法。 请查阅运行时源代码和标题,或者只使用GNUstep。