您的位置:首页 > 移动开发 > Objective-C

在Window环境下,使用CodeBlocks+GNUStep 配置Objective-C开发环境

2017-11-07 14:22 846 查看
需要的软件和工具:

1.  codeblocks-13.12-setup.exe

2.  gnustep-msys-system-0.25.1-setup.exe

http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/gnustep-msys-system-0.25.1-setup.exe

3. gnustep-core-0.25.0-setup.exe

http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/gnustep-core-0.25.0-setup.exe

4. gnustep-devel-1.1.1-setup.exe

http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/gnustep-devel-1.1.1-setup.exe

5. gnustep-cairo-0.22.1-setup.exe

http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/gnustep-cairo-0.22.1-setup.exe

(1 - 5 工具均在百度网盘      链接:http://pan.baidu.com/s/1hqCiQ9m 密码:lhff)

其中codeblocks的版本关系不大,2、3、4、5 的下载链接已经给出来了,这几个是比较老的版本了,安装的时候就用的这个,怕换了出错;

注:有的文章说2和3是必需的,4和5不是必需的,反正我都安装了。

下面说下2、3、4、5安装的问题    ,我是按着从2到 5的顺序安装的,没出问题,而且他们四个都安装在了同一个路径下  “C:\GNUstep\GNUstep”,

当然“C:\GNUstep”下也是有其他文件的;所有的安装都是默认安装就行了;

安装完成后就要配置开发环境了,这里完全按着第一篇文章   http://mobile.51cto.com/iphone-280786.htm  中介绍的过程操作即可。这里也简单的说下:

 为Code::Blocks添加编译器

打开Code::Blocks,点击菜单Settings>Compiler and debugger>Global compiler settings

在Selected compiler下拉框下面点击Copy, 在弹出窗口中填入: GNUstep MinGW Compiler

之后,点击Toolchain executables选项卡,将Compiler’s installation directory选择为C:GNUstepmingwbin

3. 创建Objective-C工程

创建一个Console的C工程,将main.c删除,新建main.m文件,内容如下:
#import <Foundation/Foundation.h> 
int main (int argc, const char *argv[]) {  
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  
    NSLog(@"Hello World!");  
    [pool drain];  
    return 0;  


右击main.m点击property,选择Build选项卡,将Compile file与Link file都打上勾,选择Advanced,将Compiler variable的内容改为CC

4. 设置编译选项

(1)方法一

右击将创建的工程,选择Build options…,Selected compiler编译器选择GNUstep MinGW Compiler, 选择Compiler settings>Other options中填入-fconstant-string-class=NSConstantString

选择Linker settings选项卡,点击Add,增加如下两行内容:
C:/GNUstep/GNUstep/System/Library/Libraries/libobjc.dll.a  
C:/GNUstep/GNUstep/System/Library/Libraries/libgnustep-base.dll.a 

选择Search directories>Compiler,点击Add,增加如下内容:
C:/GNUstep/GNUstep/System/Library/Headers 

(2)方法二

右击将创建的工程,选择Build options…,Selected compiler编译器选择GNUstep MinGW Compiler, 选择Compiler settings>Other options中填入
-fconstant-string-class=NSConstantString -IC:/GNUstep/GNUstep/System/Library/Headers  
   -LC:/GNUstep/GNUstep/System/Library/Libraries 

选择Linker settings选项卡,在Other linker options中输入-lobjc -lgnustep-base即可

5. 增加.m文件类型高亮及编辑器关联

(1)点击Settings>Editors>Syntax highlighting, 选择Syntax highlighting for: C/C++,点击Filemasks…,在弹出窗口里面加入*.m,点OK

选择Matlab,点击Filemasks…,将里面的*.m删除

(2)点击Settings>Environment>Files extension handling,点击*.m,在To open the file中选择

Open it in a Code::Blocks editor即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐