Fork me on GitHub
利用GNUstep在windows下编写object-c

首先看下GNUstep来自百度百科的特点介绍:

目前 GNU GCC 3.x 支援 Objective-C 语言, GNUstep 则提供 GNUstep Make 来简化编译 Objective-C 程式. GNUstep Make 提供类似 Makefile 的功能, 称为 GNUmakefile. 与 Makefile 相比较之下 GNUmakefile 简单许多.
  综合上述, GNUstep 实作 OpenStep 介面, 该介面已在商业市场上使用多年, 目前并演进成 MacOS X 的 Cocoa 环境. GNUstep 包含四个主要部份, 统称为核心 (Core):
  1. GNUstep Make: 提供类似 Makefile 的功能, 称为 GNUmakefile, 较 Makefile 好用许多.
  2. GNUstep Base: 提供 OpenStep 的 Foundation 程式库, 处理非图形介面的功能.
  3. GNUstep GUI: 提供 OpenStep 的 AppKit 程式库, 处理图形介面的功能.
  4. GNUstep Back: 提供与作业系统相关的后端处理, 提供 GNUstep GUI 有关绘图及字型的功能.
  简单的说 GNUstep 其实也是要打造类似 KDE 或 GNOME 的整合式环境,只是说它用 的程式语言是 Object C , 而本身也有一套 GUI Toolkits 来开发,当然先进的物件导向设计是最让人印象深刻的。

官方介绍:http://www.gnustep.org/

The purpose of this project is to create a free and open version of the Cocoa (formerly known as NeXTSTEP/OpenStep) APIs and tools for as many platforms as possible.
 
GNUstep provides a robust implementation of the AppKit and Foundation libraries as well as the development tools available on Cocoa, including Gorm <br>(the InterfaceBuilder) and ProjectCenter (ProjectBuilder/Xcode). GNUstep currently supports Unix (GNU/Linux and GNU/HURD, Solaris, NetBSD, OpenBSD, FreeBSD, Darwin) <br>and Windows.

 

下面我们介绍一下在windows下安装与使用,我的系统是 windows xp

1.下载windows版的安装包 http://www.gnustep.org/experience/Windows.html

2.从上向下安装,软件的默认安装目录是c:\GNUstep,我选择了D:\GNUstep,在安装过程中,软件的安装选项都可以选择默认项

3.软件都安装完成之后,在开始菜单->所有程序->GNUstep->shell,会弹出一个cmd命令窗口

4.我们可以通过vim helloworld.m 创建一个helloworld文件,或者我们可以通过其他的IDE工具,在d:\GNUstep\msys\1.0\home\<username>下创建文件,其中<username>是系统的登录用户名,我的就是默认的d:\GNUstep\msys\1.0\home\Administrator,第一个代码如下,代码不做解释,今天的重点就是讲下GNUstep的使用

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

 5.创建helloworld.m完成后,在命令行运行

1     gcc -o helloworld helloworld.m \  
2     -fconstant-string-class=NSConstantString \  
3     -I /GNUstep/System/Library/Headers/ \  
4     -L /GNUstep/System/Library/Libraries/ \  
5     -lobjc \  
6     -lgnustep-base  

特别注意:Be very careful about the -lobjc and -lgnustep-base switch, they must appear after file name "helloworld.m", helloword.m必须要在-lobjc and -lgnustep-base的前面

6.如果不报错误的情况下,会创建一个helloword.exe文件,我的是一次运行成功,但是在网上也看到有人运行后会报错,如下

解决办法D:\GNUstep\GNUstep\System\Library\Headers\GNUstepBase\GSConfig.h中,找到

#define BASE_NATIVE_OBJC_EXCEPTIONS     1=》#define BASE_NATIVE_OBJC_EXCEPTIONS     
之后从新编译

7.运行helloworld.exe

 

参考:http://blog.lyxite.com/2008/01/compile-objective-c-programs-using-gcc.html

      中文参考站:http://www.nongnu.org/gstutorial/zh_TW/index.html

 
分类: object-c
posted on 2012-11-12 15:52  HackerVirus  阅读(203)  评论(0编辑  收藏  举报