Object-C 之 Hello World

来源:互联网 发布:c语言中exit 0 编辑:程序博客网 时间:2024/06/05 17:59
突然想试一下object-c写程序,放到ios下试试。于是网上找了一下object-c环境搭建。基本都是通过 GNUstep平台+gcc进行交叉编译。其中,GNUstop基本组件如下:
    gnustep-make
    gnustep-base
    gnustep-gui
    gnustep-back
如果是在Windows平台,还要带上Cygwin或MinGW或msys等类unix虚拟平台。
不过在Linux下,只需一个源码包即可全部安装,非常方便!
具体如:http://wiki.gnustep.org/index.php/Startup
gnustep有一个测试工具,可以测试安装的环境是否有问题。直接运行 gnustep-tests即可。

一切顺序,赶紧试我的第一个object-c程序:Helloworld.m

#import <Foundation/Foundation.h>int main(char argc, char* argv[]) {    NSLog(@"hello world");    return 0;}

编译:

gcc -o helloworld helloworld.m -fconstant-string-class=NSConstantString -I /GNUstep/System/Library/Headers/ -L /GNUstep/System/Library/Libraries/ -lobjc -lgnustep-base

运行:

[root@cross]# lshelloworld helloworld.m[root@bogon test]# ./helloworld2013-1-21 03:34:58.355 helloworld[22916] hello world[root@cross]# 


原创粉丝点击