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这个工程来实 ...
随机推荐
- Linux(CentOS)修改IP地址
登陆连接centos系统,输入 ifconfig 可以查看到当前本机的IP地址信息 一 临时修改IP地址: 1.假如查询IP为1.118,输入 ifconfig eth0 (默认是第一个网卡) 后面接 ...
- Django的信号机制详解
Django提供一种信号机制.其实就是观察者模式,又叫发布-订阅(Publish/Subscribe) .当发生一些动作的时候,发出信号,然后监听了这个信号的函数就会执行. Django内置了一些信号 ...
- 利用velocity.js将svg动起来
关于velocity.js Velocity.js是一款jquery动画引擎插件,它拥有与jquery中的$.animate()相同的API,还打包了颜色动画,转换,循环,easing效果,类动画.滚 ...
- Android 4.4 Kitkat Phone工作流程浅析(七)__来电(MT)响铃流程
本文来自http://blog.csdn.net/yihongyuelan 转载请务必注明出处 本文代码以MTK平台Android 4.4为分析对象,与Google原生AOSP有些许差异,请读者知悉. ...
- pngCanvas 是一个使用纯Python代码的生成png图像的工具
#!/usr/bin/env python """Simple PNG Canvas for Python - updated for bytearray()" ...
- Google Chrome 浏览器的检索语言设置
解决为何从一开始安装Google Chrome 浏览器的时候,使用Google 搜索,结果都是日文的问题. 藏的比较隐蔽,没法在“设置”那里修改. 1.问题:搜索内容均是日文: 2.注意到右边有一个“ ...
- 一个由正则表达式引发的血案 vs2017使用rdlc实现批量打印 vs2017使用rdlc [asp.net core 源码分析] 01 - Session SignalR sql for xml path用法 MemCahe C# 操作Excel图形——绘制、读取、隐藏、删除图形 IOC,DIP,DI,IoC容器
1. 血案由来 近期我在为Lazada卖家中心做一个自助注册的项目,其中的shop name校验规则较为复杂,要求:1. 英文字母大小写2. 数字3. 越南文4. 一些特殊字符,如“&”,“- ...
- Mybatis(三):MyBatis缓存详解
MyBatis缓存分为一级缓存和二级缓存 一级缓存 MyBatis的一级缓存指的是在一个Session域内,session为关闭的时候执行的查询会根据SQL为key被缓存(跟mysql缓存一样,修改任 ...
- 返回当前文档的文档的url
HTML DOM referrer 属性 HTML DOM Document 对象 定义和用法 referrer 属性可返回载入当前文档的文档的 URL. 语法 document.referrer 说 ...
- 使用pycharm手动搭建python语言django开发环境 - 使用git管理代码(二)
在pycharm中打开项目,使用File->Version Control->Git.选中git的安装路径并点击确认. 2)在Version Control界面中,配置或新建一个git的主 ...