搭建CodeBlocks Objective-C windows集成开发环境
1. 安装Objective-C编译器,下载GNUStep并进行安装
将这三个程序安装到D:\GNUstep
2. 安装集成开发环境Code::Blocks
3. 配置编译环境
(1) 选择settings->compiler
(2) copy 'GNU GCC Compiler'改名为GNUstep MinGW Compiler并作如图配置:
(3)在other options中输入-fconstant-string-class=NSConstantString -std=c99
(4) 配置 Linkerstettings,在连接库(Link Libraries)中添加两个文件,如图。
它们在D:\GNUstep\GNUstep\System\Library\Libraries下面:
- libgnustep-base.dll.a
- libobjc.dll.a
(5) 配置search directories,添加D:\GNUstep\GNUstep\System\Library\Headers
(6)配置linker搜索目录为
D:\GNUstep\GNUstep\System\Library\Libraries
(7)配置toolchain路径为D:\GNUstep\bin
(8) 添加objectiv-c .m文件的支持
进入
Settings->Environment...
,选择
Files extension handling
添加
*.m
(9)
进入
Project->Project tree->Edit file types & categories...
,在
Sources
,
下面添加
*.m
到文件类型列表中
(10) 进入Settings->Editor...,选择matlab Syntaxhighlighting,点击“Filemasks....”按钮,将.m从对话框中去掉
4. 测试hello world
新建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;
}
执行效果如下: