安装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. windowsclient开发--依据可下载url另存为文件(微信windowsclient这样做的)

    能够我的blog的标题会让你误解,那么好,没图说了xx: 比方微信windowsclient发送了一张图片,我们能够预览这张图片,还能够保存到本地: 那么windows程序是怎样下载这张图片的呢? 是 ...

  2. Centos6.0 通过devtoolset-2工具安装gcc 4.8

    详细步骤: 1.Save repository information as /etc/ yum .repos.d/slc6- devtoolset.repo on your system.then ...

  3. 倍福TwinCAT(贝福Beckhoff)应用教程13.2 TwinCAT控制松下伺服 NC自定义直线插补

    对于MOVEJ的关节运动来说,我们只关心每个电机的角度(只需要考虑多个电机协同开始运动和结束运动,关键是对每个电机加速度均一化,从而一起跑一起停,这部分内容可以参考机器人学导论以获取更加详细的说明), ...

  4. java web程序中项目名的更改(http://localhost:8080/)后面的名字

    在MyEclipse中的Web项目,如果想另换名称(Context-root)进行发布,可以在项目的属性中进行设置.设置路径如下: 右击项目XX(或选中项目XX,按快捷键Alt+Enter), 打开项 ...

  5. Python——标准库 Sys模块

    ---------------------------------------------------------------------------------------------------- ...

  6. UE4 场景展示Demo

    使用到的level blueprint如下:

  7. Mvp快速搭建商城购物车模块

    代码地址如下:http://www.demodashi.com/demo/12834.html 前言: 说到MVP的时候其实大家都不陌生,但是涉及到实际项目中使用,还是有些无从下手.因此这里小编带着大 ...

  8. C#绑定事件时使用匿名函数

    当使用一些临时的函数 可以预知这些函数基本不会被复用时  可以使用匿名函数简化代码 public static void startCoupons() { //绑定一些事件 userGetCoupon ...

  9. css学习之overlay

    CSS Overlay技巧 作者:大漠 日期:2013-11-10 点击:8  本文由大漠根据SARA SOUEIDAN的<CSS OVERLAY TECHNIQUES>所译,整个译文带 ...

  10. vivado2016.2下系统自带DDR3 ip例程仿真运行

    背景:从ISE14.7迁移到vivado2016.2. xilinx的软件改的真是不一般的大.两个软件操作差距真是让人想骂人.由于项目需要,准备调试DDR3.对于新手来说,例化一个DDR3 ip.如果 ...