【转】ubuntu12.04下开发Object-C
1.安装软件:
sudo apt-get install build-essential
sudo apt-get install gcc ,g++
sudo apt-get install gobjc gnustep gnustep-devel gobjc++
2.Hello World:
#import <stdio.h>
int main(int argc, const char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@”Hello world\n”);
[pool drain];
return 0;
}
保存为 hello.m
3.编译:
gcc -fconstant-string-class=NSConstantString -o hello hello.m -I/usr/include/GNUstep -lobjc -lgnustep-base
4.运行:
./hello
我的结果:
那个mac命令是我的一个bash脚本(mac.sh),废话少说,直上代码:
#! /bin/bash ############# Setup for Object C ################## TARGET=$1 SOURCE=$2
CMD="gcc -fconstant-string-class=NSConstantString -o ${TARGET} ${SOURCE} -I/usr/include/GNUstep -lobjc -lgnustep-base" ${CMD}
说明:语法格式:mac xxx xxx.m