windows Objective-C模拟环境搭建
安装GNUstep
GNUstep Windows Installer提供了Windows平台下的Objective-C的模拟开发环境,一共有四个软件包,其中GNUstep System和GNUstep Core是必装的,GNUstep Devel和Cairo 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模拟环境搭建的更多相关文章
- 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)运行的是 ...
- Windows Mobile 6开发环境搭建
Windows Mobile 6开发环境搭建 本文主要介绍在已有的Visual Studio 2005和Microsoft SQL Server2008环境基础上,如何搭建Windows Mobile ...
- windows下面go语言环境搭建
步骤一:golang下载 下载地址是:http://www.golangtc.com/download 下载完成之后解压缩,放到你的c:/根目录下面.然后配置一下环境变量! 环境变量配置如下: 1.新 ...
- Windows下的SVN环境搭建详解
前言:最近因为要和其他人合作开发项目,所以花时间搭建了SVN的环境. 因为是初次使用SVN,对于SVN的环境搭建很不熟悉,再加上网上的教程都介绍的比较粗略,导致前前后后重做了几次. 当然最终是搭建成功 ...
- Windows 下 Ionic 开发环境搭建
Ionic 介绍 首先,Ionic 是什么. Ionic 是一款基于 Cordova 及 Angular 开发 Hybrid/Web APP 的前端框架,类似的其他框架有:Intel XDK等. 简单 ...
- 环境搭建文档——Windows下的Python3环境搭建
前言 背景介绍: 自己用Python开发了一些安卓性能自动化测试的脚本, 但是想要运行这些脚本的话, 本地需要Python的环境. 测试组的同事基本都没有安装Python环境, 于是乎, 我就想直接在 ...
- php手动搭建wamp环境(一)--之 Windows系统下PHP环境搭建
1.PHP环境搭建的前提是 Apache HTTP Server (Apache 服务器)已经安装部署成功,并可以正常访问到服务器的主页面.Apache HTTP Server 的安装部署已经在上一篇 ...
- wnmp(windows+nginx+mysql+php)环境搭建和配置
要求 必备知识 熟悉基本编程环境搭建. 运行环境 windows 7(64位); nginx-1.4.7;MySQL Server 5.5php-5.4.39-nts 下载地址 环境下载 Nginx是 ...
- [Flutter] Windows平台Flutter开发环境搭建(Andorid Studio)
前两天网友在群里说起了Flutter,就了解了一下,在手机上跑了它的demo,直接就被打动了. 虽然网上有很多教程,但真正开始的时候,还是会碰到很多坑.下面详细的讲解Flutter + Android ...
- Windows Phone Unit Test 环境搭建
单元测试对工程质量带来的作用就不详细说明了,本文只讨论如何在WP开发环境下搭建测试工程 历史 从WP7时代官方是不支持UnitTest工程的,因此需要采用WPToolkitTest这个工程来实 ...
随机推荐
- 验收测试 - WebDriver 5
验收测试 - WebDriver - 配置 什么是WebDriver 这样说好了,它翻译起来就是Web驱动,用我的经验来说,它就是驱动浏览器运行的一个驱动器 有什么作用? 就像一个司机可以驱动一台汽车 ...
- map-reduce任务的执行流程
(1).客户端提交一个mr的jar包给JobClient(提交方式:hadoop jar ...) (2).JobClient通过RPC和JobTracker进行通信,返回一个存放jar包的地址(HD ...
- Accessing Report Server using Report Server Web Service - Microsoft SQL Server 2008R2
Today I am going to write about how to access SQL Server Report Server through Report Server Web ser ...
- JSONObject和JSONArray(json-lib-2.4)的基本用法
json-lib-2.4是一个用于JSON和java对象间转换的第三方包,其jar和依赖包下载地址在:https://files.cnblogs.com/files/xiandedanteng/jso ...
- 可伸缩Web架构与分布式系统(1)
开源软件近年来已变为构建一些大型网站的基础组件.并且伴随着网站的成长,围绕着它们架构的最佳实践和指导准则已经显露.这篇文章旨在涉及一些在设计大型网站时需要考虑的关键问题和一些为达到这些目标所使用的组件 ...
- [Unity3D]查看与设置游戏帧数FPS
原地址:http://blog.sina.com.cn/s/blog_5b6cb9500101bta4.html 关于FPS,在PC端来说,游戏帧数跑得越高越好,FPS跑得越高游戏就越流畅,当然太高也 ...
- PHP中单引号双引号使用原则
PHP中单引号双引号使用原则 1.PHP中尽量用单引号,HTML代码全部用双引号 2.在包含变量的时候,用双引号可以简化操作 3.复杂的情况下用大括号包起来 4 PHP引号还有一个用处 ...
- lodash random
_.random([min=0], [max=1], [floating]) 产生一个包括 min 与 max 之间的数. 如果只提供一个参数返回一个0到提供数之间的数. 如果 floating 设为 ...
- Easy Explore插件:在eclipse里快速打开文件所在的目录
下载:easyexplore_1.0.4 安装:把文件”org.sf.easyexplore_1.0.4.jar”文件解压出来,然后复制到eclipse安装目录的”plugins”文件夹里 http: ...
- linux-centos7中lnmp服务器编译安装含systemctl启动service(转)
centos7 nginx mysql php 可以分开安装 然后在配置nginx互php的 先安装一些必要的库 ---------------------------------------- ...