Windows下安装Object C开发环境,及Hello Word

最近想学习iphone开发,但是由于没有c基础,只有java基础。所以先从基础学习,首先是搭建环境,目前手头没有mac机子,只能先在windows下学习基本语法。还好找到了GNUset,可以利用GNUstep在windows下模拟object c开发环境。

官方网址:http://www.gnustep.org/

安装:

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

编写HelloWord

几乎所有的开发环境都是以HelloWord开始,在这里我们先编写HelloWord.

安装完成后,在开始菜单里的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+0×33): undefined reference to `_objc_get_class’ 
helloworld.m:(.text+0×45): undefined reference to `_objc_msg_lookup’ 
helloworld.m:(.text+0×64): undefined reference to `_objc_msg_lookup’ 
helloworld.m:(.text+0×80): undefined reference to `_NSLog’ 
helloworld.m:(.text+0×93): undefined reference to `_objc_msg_lookup’ 
helloworld.m:(.text+0xbc): undefined reference to `___objc_exec_class’ 
helloworld.m:(.data+0×74): undefined reference to `___objc_class_name_NSAutoreleasePool’ 
helloworld.m:(.data+0×78): 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

执行上面的路径还是会提示找不到Foundation/Foundation.h 需要加上绝对路径,命令:

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

注意:helloworld.m必须出现在-lobjc和-lgnustep-base的前面,否则会出错。 
此时会出现一些info提示信息,不过不碍事,终于成功了生成了可执行文件,执行看结果。

./helloworld.exe     windows命令行:helloworld

结果是:

注意,可以利用粘贴复制命令:Ctrl+p

Windows下安装Object C开发环境,及Hello Word(转)的更多相关文章

  1. 【转】linux和windows下安装python集成开发环境及其python包

    本系列分为两篇: 1.[转]windows和linux中搭建python集成开发环境IDE 2.[转]linux和windows下安装python集成开发环境及其python包 3.windows和l ...

  2. python_在windows下安装配置python开发环境及Ulipad开发工具

    最近开始学习Python,在网上寻找一下比较好的IDE.因为以前用C#做开发的,用Visual Studio作为IDE,鉴于用惯了VS这么强大的IDE,所以对IDE有一定的依赖性. Python的ID ...

  3. 在windows下安装配置python开发环境及Ulipad开发工具(转)

    最近开始学习Python,在网上寻找一下比较好的IDE.因为以前用C#做开发的,用Visual Studio作为IDE,鉴于用惯了VS这么强大的IDE,所以对IDE有一定的依赖性. Python的ID ...

  4. Windows下安装PHP及开发环境配置

    一.Apache 因为Apache官网只提供源代码,如果要使用必须得自己编译,这里我选择第三方安装包Apache Lounge. 1. 进入Apachelounge官方下载地址:http://www. ...

  5. Windows下搭建Spark+Hadoop开发环境

    Windows下搭建Spark+Hadoop开发环境需要一些工具支持. 只需要确保您的电脑已装好Java环境,那么就可以开始了. 一. 准备工作 1. 下载Hadoop2.7.1版本(写Spark和H ...

  6. Windows下的Objective-C集成开发环境(IDE)

    Windows下的Objective-C集成开发环境(IDE) 分类: Objective-C2012-04-20 21:54 26631人阅读 评论(42) 收藏 举报 windowside编译器c ...

  7. Windows下搭建objective C开发环境

    摘自:http://blog.csdn.net/zhanghefu/article/details/18320827 最近打算针对iPhone.iPod touch和iPad开发一些应用,所以,需要开 ...

  8. windows下搭建nginx+php开发环境

    windows下搭建nginx+php开发环境 1.前言 windows下大多我们都是下载使用集成环境,但是本地已经存在一个集成环境,但不适合项目的需求.因此准备再自己搭建一个环境. 2.准备 工具: ...

  9. Windows下快速搭建安卓开发环境android-studio

    Windows下快速搭建安卓开发环境android-studio 发布时间:2018-01-18 来源:网络 上传者:用户 关键字: 安卓 搭建 Android Windows 快速 环境 Studi ...

随机推荐

  1. c语言字符处理函数常见使用集合

    1.最近看一些开源项目代码时,总会看到 c 语言中一些  "str" 开头的处理字符串的用法,有的之前没用到过,特此记录,随时看到随时添加. 这里不提出源码,只是一些使用说明加例子 ...

  2. windows远程登录最大连接数

  3. define用于条件编译

    格式: #ifndef _test.h_ //这里放不想被重复包含的代码 #define _test.h_ #endif define用于条件编译的意思是不想让头文件重复编译,头文件重复编译会造成的结 ...

  4. Java小程序之输出星号

    题目:打印出如下图案(菱形)     *    ***  ****** ********  ******   ***    * 编程工具使用eclipse 代码如下: package test; pu ...

  5. SSL和SSH的区别

    SSL是一种国际标准的加密及身份认证通信协议,您用的浏览器就支持此协议.SSL(Secure Sockets Layer)最初是由美国Netscape公司研究出来的,后来成为了Internet网上安全 ...

  6. 【C#基本功 控件的用法】 Toolbar的用法

    之前从事Labview编程,Labview是一门快速编程的语言,虽然快速,但作为一门语言他灵活性不够,有些方面也不是很给力,就比如 Toolbar labview就没有Toolbar的基础控件,虽然可 ...

  7. OpenStack Mitaka HA部署方案(随笔)

    [Toc] https://github.com/wanstack/AutoMitaka # 亲情奉献安装openstack HA脚本 使用python + shell,完成了基本的核心功能(纯二层的 ...

  8. PetaPoco入门

    (转自:http://www.cnblogs.com/tinyhu/archive/2013/06/02/3113652.html) 1. ORM概括 1.1. ORM简介 ORM 对象-关系映射(O ...

  9. Struts01---入门小案例

    创建web项目    实现的效果! 用户点击页面不同的链接,后台调用不同的代码! 创建两个类实现共同的接口! public interface Action { String execute(); } ...

  10. ASP.NET学习路线图(转)

    如果你已经有较多的面向对象开发经验,跳过以下这两步: 第一步 掌握一门.NET面向对象语言,C#或VB.NET 我强烈反对在没系统学过一门面向对象(OO)语言的前提下去学ASP.NET. ASP.NE ...