CodeBlocks集成Objective-C开发

1. 首先安装Objective-C编译器

GNUstep Windows Installer提供了Windows平台下的Objective-C的模拟开发环境,一共有四个软件包,其中GNUstep System和GNUstep Core是必装的,GNUstep Devel和Cairo Backend是选装的。甭管必装选装,一次性全安上,免得以后麻烦。

四个文件都安装到C:GNUstep下

http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/gnustep-msys-system-0.25.1-setup.exe
http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/gnustep-core-0.25.0-setup.exe
http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/gnustep-devel-1.1.1-setup.exe
http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/gnustep-cairo-0.22.1-setup.exe


2. 为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即可

 
 
 
转载之外:
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值