是否有任何方法可以在不使用GNUStep的情況下編譯ubuntu上的目標c程序?我想使用默認的C標準庫,除了Objective-C的OOB語法外。我現在面臨的問題是一旦我有了所有的方法,我需要一種方法來調用它們。在Mac中,我只是分配和初始化它,但在Linux上嘗試編譯時,clang只是給了我一個錯誤...任何幫助將非常感激。在沒有gnustep的情況下編譯目標c程序
#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"];
}
哪裏是你的執行情況'alloc'和'init'從哪兒來沒有GNUstep的(或Objective-C的運行時庫)? –
是啊有沒有辦法從沒有'alloc'或'init'的實現中調用方法? –
現代GNUstep運行時既沒有實現+ alloc也沒有實現-init。如果你想要它們,你可以覆蓋任何地方的實現。 + alloc的實現應該只調用class_createInstance(...)請查閱您的.h以獲取其餘必需的API。你可能也想考慮如何使用@autorelease ie。如何管理保留櫃檯等。我不知道爲什麼一個人真的想要走這條路,只需安裝GNUstep基礎。 –