sudo apt-get update sudo apt-get install gnustep*
包含 gcc-objc、gnustep-make、gnustep-base 等核心套件。
編輯 ~/.bashrc 或 ~/.profile 加入:
export GNUSTEP_ROOT=/usr/share/GNUstep/Makefiles source /usr/share/GNUstep/Makefiles/GNUstep.sh
套用變更:source ~/.bashrc
建立 hello.m(Objective-C 慣用 .m 副檔名):
#import <Foundation/Foundation.h>
int main(int argc, const char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Hello World!\n");
[pool drain];
return 0;
}
同目錄建立 GNUmakefile:
include $(GNUSTEP_ROOT)/common.make TOOL_NAME = HelloWorld HelloWorld_OBJC_FILES = hello.m include $(GNUSTEP_ROOT)/tool.make
make
成功後在 obj/ 目錄產生執行檔:
./obj/HelloWorld 2014-05-04 07:07:35.340 HelloWorld[15727] Hello World!
NSAutoreleasePool:手動記憶體管理機制(非 ARC 環境)NSLog:Foundation 框架記錄函數,含時間戳與程式名GNUmakefile 需與 GNUSTEP_ROOT 環境變數一致現代 Ubuntu 版本建議改用 clang + libobjc2 + GNUstep 組合,支援更多現代語法特性(如 ARC、Blocks、字面值語法)。