1. 安装编译环境php
Object C和其余不少语言同样,都须要有一个编译器。Object C 是在GCC下编译的。GCC(GNU Compiler Collection,GNU编译器集合),是一套由 GNU 开发的编程语言编译器。不少人想到学习Object C就想到mac电脑,想到XCode开发工具。其实在Windows环境一下也能够编译Object C。html
首先下载Windows版本的GCC编译器,下载地址:http://wwwmain.gnustep.org/resources/downloads.php编程
下载以下几个包:windows
gnustep-system-0.23.0-setup.exe gnustep-core-0.23.0-setup.exe gnustep-devel-1.0.0-setup.exe gnustep-cairo-0.22.1-setup.exe编程语言
以上四个包点击连接能够下载,下载以后安装顺序安装,前面两个包是必选的,后面两个是可选安装的。工具
2. 安装IDE开发环境学习
CodeBlocks IDE是一个开源跨平台的C++ 开发工具。其官网地址:http://www.codeblocks.org/开发工具
下载地址以下:http://www.codeblocks.org/downloads/26测试
工具界面如图:ui
3. 配置编译环境
安装好工具以后,打开如上图界面,在导航菜单栏中找到Settings--Compiler Settings
从新命名为"GNUstep MinGW Compiler", 大部分人都是这么命名的。而后Set as default
编译设置参数:选择Compiler Settings 选项卡中选择Other Options选项卡,在其中输入: "-fconstant-string-class=NSConstantString -std=c99"
设置Linker Settings:在"\GNUstep\GNUstep\System\Library\Libraries\" 安装目录下找到 libgnustep-base.dll.a libobjc.dll.a 两个文件
设置Search directories : 将"\GNUstep\GNUstep\System\Library\Headers" 目录配置到Compiler选项中
4. 配置语法、文件类型,关键字等
(1)进入Settings->Environment...
(2)选择 Files extension handling 添加*.m
(3)进入 Project->Project tree->Edit file types & categories...
(4)在Sources, 下面添加 *.m到文件类型列表中.
5. 新建工程,测试Object C
新建一个控制台程序,如上图所示:
#import <Foundation/Foundation.h> int main (int argc, const char *argv[]) { NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init]; NSLog(@"%@",@"第一个测试程序"); [pool drain]; return 0; }
点击Build - run 或者 Ctrl + F10 ,编译报错:
ERROR: You need to specify a debugger program in the debuggers's settings.
(For MinGW compilers, it's 'gdb.exe' (without the quotes))
(For MSVC compilers, it's 'cdb.exe' (without the quotes))
如上问题须要设置一下:Settings--Compiler Settings--Toolchain executables
点击Auto-detect 以后会自动设置相应的环境配置,而后从新编译便可. 运行效果以下: