安装GNUstep

GNUstep Windows Installer提供了Windows平台下的Objective-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+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

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

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

快捷方式:

如果每次使用gcc的时候,都要输入这么长的命令,无疑是很恼火的事儿,我们可以做一个快捷方式:

编辑C:\GNUstep\bin\gcc.sh的文件,内容如下:

#!/bin/sh

if [ $# -ne 1 ]; then
echo "Usage: $0 name"
exit 1
fi

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

exit 0

其中,gcc加入了-g参数,方便gdb调试,使用时就很方便了,注意别带扩展名m:

gcc.sh helloworld

参考链接:

Compile Objective-C Programs Using gcc
http://blog.joomla.org.tw/mobile/59-iphone/103-objective-c-gnustep.html

windows Objective-C模拟环境搭建的更多相关文章

  1. Windows 10 IoT Serials 1 - 针对Minnow Board MAX的Windows 10 IoT开发环境搭建

    目前,微软针对Windows IoT计划支持的硬件包括树莓派2,Minnow Board MAX 和Galileo (Gen 1和Gen 2).其中,Galileo (Gen 1和Gen 2)运行的是 ...

  2. Windows Mobile 6开发环境搭建

    Windows Mobile 6开发环境搭建 本文主要介绍在已有的Visual Studio 2005和Microsoft SQL Server2008环境基础上,如何搭建Windows Mobile ...

  3. windows下面go语言环境搭建

    步骤一:golang下载 下载地址是:http://www.golangtc.com/download 下载完成之后解压缩,放到你的c:/根目录下面.然后配置一下环境变量! 环境变量配置如下: 1.新 ...

  4. Windows下的SVN环境搭建详解

    前言:最近因为要和其他人合作开发项目,所以花时间搭建了SVN的环境. 因为是初次使用SVN,对于SVN的环境搭建很不熟悉,再加上网上的教程都介绍的比较粗略,导致前前后后重做了几次. 当然最终是搭建成功 ...

  5. Windows 下 Ionic 开发环境搭建

    Ionic 介绍 首先,Ionic 是什么. Ionic 是一款基于 Cordova 及 Angular 开发 Hybrid/Web APP 的前端框架,类似的其他框架有:Intel XDK等. 简单 ...

  6. 环境搭建文档——Windows下的Python3环境搭建

    前言 背景介绍: 自己用Python开发了一些安卓性能自动化测试的脚本, 但是想要运行这些脚本的话, 本地需要Python的环境. 测试组的同事基本都没有安装Python环境, 于是乎, 我就想直接在 ...

  7. php手动搭建wamp环境(一)--之 Windows系统下PHP环境搭建

    1.PHP环境搭建的前提是 Apache HTTP Server (Apache 服务器)已经安装部署成功,并可以正常访问到服务器的主页面.Apache HTTP Server 的安装部署已经在上一篇 ...

  8. wnmp(windows+nginx+mysql+php)环境搭建和配置

    要求 必备知识 熟悉基本编程环境搭建. 运行环境 windows 7(64位); nginx-1.4.7;MySQL Server 5.5php-5.4.39-nts 下载地址 环境下载 Nginx是 ...

  9. [Flutter] Windows平台Flutter开发环境搭建(Andorid Studio)

    前两天网友在群里说起了Flutter,就了解了一下,在手机上跑了它的demo,直接就被打动了. 虽然网上有很多教程,但真正开始的时候,还是会碰到很多坑.下面详细的讲解Flutter + Android ...

  10. Windows Phone Unit Test 环境搭建

    单元测试对工程质量带来的作用就不详细说明了,本文只讨论如何在WP开发环境下搭建测试工程     历史 从WP7时代官方是不支持UnitTest工程的,因此需要采用WPToolkitTest这个工程来实 ...

随机推荐

  1. java中short、int、long、float、double取值范围

    一.分析基本数据类型的特点,最大值和最小值.1.基本类型:int 二进制位数:32包装类:java.lang.Integer最小值:Integer.MIN_VALUE= -2147483648 (-2 ...

  2. Win7如何改变用户文件夹位置

    现在装WIN7后第一件就是改变用户账户文件夹位置..因为里面存着一些软件的设定和信息等..不必要每次装后都手动改一次.. 已前用优化大师改.太麻烦.也不稳定有时有些目录不能完全改过来.. 通过命令mk ...

  3. NodeJS实战——创建基础应用并应用模板引擎

    本次的目的是搭建一个最基础忽地可以实现功能的NodeJSserver,可以体现出NodeJS的工作流程以及开发的基本框架. 需求:已经安装了nodejs以及express. 一.构建基础的NodeJS ...

  4. js 自定义事件 包含 添加、激活、销毁

    1.思路 (1)构思 var eventTarget = { addEvent: function(){ //添加事件 }, fireEvent: function(){ //触发事件 }, remo ...

  5. CSS/JavaScript hacks,browserhacks使用

    1.网址 http://browserhacks.com/ 2.使用 (1)JavaScript Hacks 浏览器js判断 (2)条件注释hack (3)Media Query Hacks 媒体查询 ...

  6. 基于python的ardrone control源码分析与心得

    这里有一段python代码,可用于操控ardrone 2.0.实验室曾经借鉴用过,并添加了部分功能.如今复习一下,顺便理理python的相关知识点. #!/usr/bin/env python # A ...

  7. ssl中间证书

    中间证书,其实也叫中间CA(中间证书颁发机构,Intermediate certificate authority, Intermedia CA),对应的是根证书颁发机构(Root certifica ...

  8. SQL 子查询 EXISTS 和 NOT EXISTS

    MySQL EXISTS 和 NOT EXISTS 子查询语法如下: SELECT … FROM table WHERE EXISTS (subquery) 该语法可以理解为:将主查询的数据,放到子查 ...

  9. Atitit.js跨域解决方案attilax大总结 后台java php c#.net的CORS支持

    Atitit.js跨域解决方案attilax大总结 后台java php c#.net的CORS支持 1. 设置 document.domain为一致  推荐1 2. Apache 反向代理 推荐1 ...

  10. Atitit.文件搜索工具 attilax 总结

    Atitit.文件搜索工具 attilax 总结 1. 指定目录按照体积大小精确搜索1 1.1. File Seeker 4.5 版本的可以,3.5版本的不行..1 2. 按照文件内容搜索1 2.1. ...