手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆

感谢老王的:Object-C之Windows版Hello, World!

首页 > Software >

感谢老王这篇文章,本来有自己想办法看看是不是能搞个ipt来玩玩。然后想自己学点苹果的开发语言的。
结果买了本object-c的书回来一看,人家上面就写了object-c是安装在mac下面的。当时,心都碎了
书也扔在那里几个月了。本以为这将进40块钱的书就算是扔了水里了。谁知道老王又贡献了这么一篇文章。很是感动。。。

老王说:

Mac笔记本实在是太贵了,所以一直没舍得买,如此一来,就只能在我的Windows操作系统上学Object-C了。

安装GNUstep

GNUstep Windows Installer提供了Windows平台下的Object-C的模拟开发环境,一共有四个软件包,其中GNUstep SystemGNUstep Core是必装的,GNUstep DevelCairo Backend是选装的。甭管必装选装,一次性全安上,免得以后麻烦。

编写Hello, World!

安装完成后,在开始菜单里的GNUstep选项里执行shell,就能打开命令行,在这里就可以使用vi编写Object-C程序了,不过操作起来总有些繁琐,其实也可以直接在Windows里进入C:\GNUstep\home\username目录,在这里用你喜欢的工具编写Object-C程序,然后再进入shell里编译。

直接给出helloworld.m文件内容,取自Programming in Objective-C 2.0一书:

#import <Foundation/Foundation.h>

int main (int argc, const char *argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSLog(@"Hello World!");
    [pool drain];

    return 0;
}


第一次编译:

gcc -o helloworld helloworld.m

结果出现错误信息,找不到头文件:

helloworld.m:1:34: Foundation/Foundation.h: No such file or directory
helloworld.m: In function `main':
helloworld.m:4: error: `NSAutoreleasePool' undeclared (first use in this function)
helloworld.m:4: error: (Each undeclared identifier is reported only once
helloworld.m:4: error: for each function it appears in.)
helloworld.m:4: error: `pool' undeclared (first use in this function)
helloworld.m:5: error: cannot find interface declaration for `NXConstantString'

第二次编译:

gcc -o helloworld helloworld.m \
-I /GNUstep/System/Library/Headers/

结果出现错误信息,找不到接口声明:

helloworld.m: In function `main':
helloworld.m:5: error: cannot find interface declaration for `NXConstantString'

第三次编译:

gcc -o helloworld helloworld.m \
-fconstant-string-class=NSConstantString \
-I /GNUstep/System/Library/Headers/

结果出现错误信息,找不到链接库:

helloworld.m:(.text+0x33): undefined reference to `_objc_get_class'
helloworld.m:(.text+0x45): undefined reference to `_objc_msg_lookup'
helloworld.m:(.text+0x64): undefined reference to `_objc_msg_lookup'
helloworld.m:(.text+0x80): undefined reference to `_NSLog'
helloworld.m:(.text+0x93): undefined reference to `_objc_msg_lookup'
helloworld.m:(.text+0xbc): undefined reference to `___objc_exec_class'
helloworld.m:(.data+0x74): undefined reference to `___objc_class_name_NSAutoreleasePool'
helloworld.m:(.data+0x78): undefined reference to `___objc_class_name_NSConstantString'
collect2: ld returned 1 exit status

第四次编译:

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

注意:helloworld.m必须出现在-lobjc和-lgnustep-base的前面,否则会出错。

此时会出现一些info提示信息,不过不碍事,终于成功了生成了可执行文件,执行./helloworld.exe看结果。

参考链接:Compile Objective-C Programs Using gcc




本站采用创作共享版权协议, 要求署名、非商业和保持一致. 本站欢迎任何非商业应用的转载, 但须注明出自"易栈网-膘叔", 保留原始链接, 此外还必须标注原文标题和链接.

Tags: object-c, windows

« 上一篇 | 下一篇 »

只显示10条记录相关文章

wubi惊魂 (浏览: 25579, 评论: 2)
惊心动魄的几小时 (浏览: 24473, 评论: 3)
Windows下SVN服务器的架设 (浏览: 23874, 评论: 0)
为windows的WEB服务器添加高性能的FTP组件 (浏览: 21563, 评论: 0)
Ubuntu创始人:Linux的未来并不在于对Windows的兼容性 (浏览: 20417, 评论: 1)
Windows Server 2008登陆Dreamspark 免费使用 (浏览: 19598, 评论: 0)
盗版WINDOWS要被大动作处理了 (浏览: 19373, 评论: 1)
【科普贴】话说回车和换行 (浏览: 19066, 评论: 0)
ZZ:IIS7在Windows Server 2008 R2中的新改进 (浏览: 18947, 评论: 0)
怎样让文件目录与VirtualBox中的虚拟机共享 (浏览: 18855, 评论: 0)

3条记录访客评论

不错不错,学习一下~

Post by zhaiduo on 2010, August 12, 4:17 PM 引用此文发表评论 #1

哈哈,其实我一次编译通过,感觉很high咯

Post by anfy on 2010, May 1, 12:24 PM 引用此文发表评论 #2

fgfgfffffffffffffffffff

Post by gfgfg on 2010, March 31, 11:00 AM 引用此文发表评论 #3


发表评论

评论内容 (必填):