---
title: "Objective C 学习心得 （一）"
author: "dxm1986"
date: "2011-11-15T14:16:05Z"
tags: []
categories: ["互联网"]
slug: "objective-c"
draft: false
lastmod: "2011-11-15T14:16:05Z"
id: 1260199
url: "https://wolfdream.iteye.com/blog/1260199"
---

### [Objective C 学习心得 （一）：--Windows下搭建objective C开发环境](http://blog.csdn.net/waden/article/details/5765294 "Objective C 学习心得 （一）：--Windows下搭建objective C开发环境")

分类： [objective c](http://blog.csdn.net/waden/article/category/714806)2010-07-25 23:37 8955人阅读 [评论](http://blog.csdn.net/waden/article/details/5765294#comments)(17) [收藏](http://blog.csdn.net/waden/article/details/5765294 "收藏") [举报](http://blog.csdn.net/waden/article/details/5765294#report "举报")

      最近打算针对iPhone、iPod touch和iPad开发一些应用，所以，需要开始学习Objective C（苹果推出的类似C语言的开发语言）。由于苹果的自我封闭的产业链发展模式（从芯片、机器、开发语言、终端产品、服务）的限制，要想开发针对苹果iPhone等产品的应用程序，就需要用Mac机器，在Xcode的IDE上使用Objective C语言开发。Mac机器就不用说了，那比PC机器要贵不少（当然性价比还是很高的），所以，要想廉价方式学习Objective C就必须要在Windows上能搭建一个Objective C开发环境。好了，不说废话了。

      在Windows下搭建Objective C开发环境，需要到GNUstep官方网站上下载，四个软件包：[GNUstep MSYS System](http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/gnustep-msys-system-0.25.1-setup.exe)、[GNUstep Core](http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/gnustep-core-0.25.0-setup.exe)、[GNUstep Devel](http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/gnustep-devel-1.1.1-setup.exe)、[Cairo Backend](http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/gnustep-cairo-0.22.1-setup.exe)。其中，前两个软件包是必须要安装的，第三个软件包是安装一些开发工具，比如：gcc、g++等，所以如果是学习Objective C的话，这个包也是必须要安装，第四个软件包是安装glib等库，这个包安装不安装根据具体情况而定。

     至于[GNUstep](http://www.gnustep.org/)是什么东西，有什么用处，这里做个简单的介绍：GNUstep就是提供类似Cocoa（苹果OS的开发框架）的API和工具，目前支持GNU/Linux and GNU/HURD, Solaris, NetBSD, OpenBSD, FreeBSD, Darwin和Windows，免费使用的。这个项目使Objective C能在多数流行平台上开发和运行。有关详细的介绍开始参考[GNUstep](http://www.gnustep.org/)的官方网站。

    言归正传，下载上述软件包后，点击安装就可以了。然后，需要确认是否安装成功，并且是否能成功编译Objective C代码。

    在“开始”菜单中“所有程序”下可以找到“GNUstep”-&gt;“shell”，就会出console窗口，可以试试一些Linux命令（ls,cd,mkdir等）。

    编写一个Objective C代码进行编译运行测试。在这里就用经典的“hello world”来说明：

 

[view plain](http://blog.csdn.net/waden/article/details/5765294 "view plain")

1. #import &lt;Foundation/Foundation.h&gt;
2. int main (int argc, const char \*argv\[]) {
3. NSAutoreleasePool \*pool=\[\[NSAutoreleasePool alloc] init];
4. NSLog(@"Hello World!");
5. \[pool drain];
6. return 0;
7. }

 

    在Windows环境下用文本编辑器（Editplus，UE等），编写上述代码，并且保存到GNUstep安装目录下的/home下，取名为helloworld.m。在GNUstep的console窗口命令行下，

    1、cd /home

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

    3、运行helloworld.exe

   说明：第二步中的一些参数明说，如果熟悉Linux/Unix下C/C++编译的话，上述参数应该很熟悉，-I表示头文件查找的路径，-L表示库文件查找路径，-l表示需要链接的库文件。但是，-fconstant-string-class=NSConstantString  对于这个参数可能比较陌生，这个参数主要是指定常量字符串所使用的class。  

    helloworld.exe编译并运行成功的话，说明windows下Objective C开发环境就搭建好了，这样就可以开始以廉价方式的学习Objective C。:)

 

转：[http://blog.csdn.net/waden/article/details/5765294](http://blog.csdn.net/waden/article/details/5765294)