[转]在 Ubuntu 中使用 GNUstep 搭建 Objective-C 开发环境
2015-12-14 16:27
645 查看
GNUstep 介绍见 http://www.gnustep.org/。
直接 apt-get install 搞定。
build-essential
gnustep
gnustep-devel
gnustep-examples
gobjc
gobjc++
为了方便使用 GNUstep 的各种编译工具,需要先在 .bashrc 中导入 GNUstep 的脚本。
使用 Makefile 来编译 Objective-C App,注意 Makefile 的文件名为 GNUmakefile。
这个是编译出 Mac OS App Bundle 形式的目标,如果是编译命令行工具的话,可以使用如下 Makefile:
在编译命令行工具时,AppKit 就不会自动链接进来了,使用 NSColor 这样的类就会有问题。
一个最简单的 HelloWorld 代码:
保存为 HelloWorld.m,编写 Makefile:
保存 Makefile 为 GNUmakefile,执行 make,会在当前目录生成 HelloWorld.app,使用 openapp 命令运行:
当然如果是编译成命令行工具的目标的话,会在当前目录的 obj 目录中生成 HelloWorld 可执行文件,这个可以直接从命令行运行:
http://www.gnustep.org/
http://www.qiongbupa.com/archives/678
http://www.gnustep.org/resources/documentation/User/GNUstep/gnustep-howto_4.html#SEC8
http://www.gnustep.it/nicola/Tutorials/WritingMakefiles/node6.html
http://www.gnustep.it/nicola/Tutorials/index.html
安装相关程序
直接 apt-get install 搞定。build-essential
gnustep
gnustep-devel
gnustep-examples
gobjc
gobjc++
设置环境变量
为了方便使用 GNUstep 的各种编译工具,需要先在 .bashrc 中导入 GNUstep 的脚本。# Setup GNUstep GNUSTEP_MAKEFILES=/usr/share/GNUstep/Makefiles export GNUSTEP_MAKEFILES source $GNUSTEP_MAKEFILES/GNUstep.sh
编写 Makefile
使用 Makefile 来编译 Objective-C App,注意 Makefile 的文件名为 GNUmakefile。include $(GNUSTEP_MAKEFILES)/common.make APP_NAME=HelloWorld HelloWorld_OBJC_FILES=test.m include $(GNUSTEP_MAKEFILES)/application.make
这个是编译出 Mac OS App Bundle 形式的目标,如果是编译命令行工具的话,可以使用如下 Makefile:
include $(GNUSTEP_MAKEFILES)/common.make TOOL_NAME=HelloWorld HelloWorld_OBJC_FILES=test.m include $(GNUSTEP_MAKEFILES)/tool.make
在编译命令行工具时,AppKit 就不会自动链接进来了,使用 NSColor 这样的类就会有问题。
HelloWorld
一个最简单的 HelloWorld 代码:#import <Foundation/Foundation.h> int main() { NSAutoreleasePool *pool = [NSAutoreleasePool new]; NSLog(@"HelloWorld"); [pool release]; return 0; }
保存为 HelloWorld.m,编写 Makefile:
include $(GNUSTEP_MAKEFILES)/common.make APP_NAME=HelloWorld HelloWorld_OBJC_FILES=HelloWorld.m include $(GNUSTEP_MAKEFILES)/application.make
保存 Makefile 为 GNUmakefile,执行 make,会在当前目录生成 HelloWorld.app,使用 openapp 命令运行:
openapp ./HelloWorld.app
当然如果是编译成命令行工具的目标的话,会在当前目录的 obj 目录中生成 HelloWorld 可执行文件,这个可以直接从命令行运行:
./obj/HelloWorld
参考资料
http://www.gnustep.org/http://www.qiongbupa.com/archives/678
http://www.gnustep.org/resources/documentation/User/GNUstep/gnustep-howto_4.html#SEC8
http://www.gnustep.it/nicola/Tutorials/WritingMakefiles/node6.html
http://www.gnustep.it/nicola/Tutorials/index.html
相关文章推荐
- Objective-C 引用计数:不讲用法,只说原理
- 借鉴 C# 关于 LINQ 的设计思想用 C++ 11 来实现 LINQ to Object
- Objective-C AES128 Encrypt And Decrypt
- Android属性动画的学习_ObjectAnimator
- WaitForSingleObject 结束线程
- Objective-C Runtime
- 黑马程序员---Java基础---Object类
- android JSON获取值String无法转换成JSONObject
- IOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnumerator
- html之object标签的classid收集
- Objective-C路成魔【18-复制对象】
- Objective-C 汤姆猫动画实现
- Objective-c语言_对可变字符串操作的常用方法
- Objective-c语言_对字符串操作的常用方法
- Objective-c语言_基本数据类型封装和拆包
- JSON中JObject和JArray,JValue序列化(Linq)
- foundation的使用——NSDate
- Java中Object类hashCode的实现
- Objective-C Runtime与黑客帝国
- Object-C @class与#import区别