如何在Windows环境搭建Object C开发环境

1. 安装编译环境

    Object C和其他很多语言一样,都需要有一个编译器。Object C 是在GCC下编译的。GCC(GNU Compiler Collection,GNU编译器集合),是一套由 GNU 开发的编程语言编译器。很多人想到学习Object C就想到mac电脑,想到XCode开发工具。其实在Windows环境一下也可以编译Object C。

    首先下载Windows版本的GCC编译器,下载地址:http://wwwmain.gnustep.org/resources/downloads.php

    下载如下几个包:

    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

    工具界面如图:

3. 配置编译环境

  安装好工具之后,打开如上图界面,在导航菜单栏中找到Settings--Compiler Settings 

重新命名为"GNUstep MinGW Compiler", 大部分人都是这么命名的。然后Set as default

编译设置参数:选择Compiler Settings 选项卡中选择Other Options选项卡,在其中输入: "-fconstant-string-class=NSConstantString -std=c99"

设置Linker Settings:在"GNUstepGNUstepSystemLibraryLibraries" 安装目录下找到 libgnustep-base.dll.a   libobjc.dll.a 两个文件

设置Search directories : 将"GNUstepGNUstepSystemLibraryHeaders" 目录配置到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 之后会自动设置相应的环境配置,然后重新编译即可. 运行效果如下:

转自http://www.cnblogs.com/qingyuan/p/3543991.html

原文地址:https://www.cnblogs.com/Bonker/p/3545622.html