Windows下配置Objective-C開發環境
一、IDE的安裝(Code::Blocks)
我們選用Code::Blocks作為IDE,它的安裝包可以從網上各處下載下來,對版本無特別要求。筆者使用的是16.10的版本(鏈接: https://pan.baidu.com/s/1l7EtMVWBCffuCVHaF3-tQg 密碼: 85ie)
具體安裝細節我就不寫了。
二、編譯工具的安裝(GNUStep)
我們需要如下的六個安裝包:
ProjectCenter-0.5.0-setup.exe(http://ftp.gnustep.org/pub/gnustep/binaries/windows/ProjectCenter-0.5.0-setup.exe)
gnustep-cairo-0.22.0-setup.exe(http://ftp.gnustep.org/pub/gnustep/binaries/windows/gnustep-cairo-0.22.0-setup.exe)
gnustep-core-0.22.0-setup.exe(http://ftp.gnustep.org/pub/gnustep/binaries/windows/gnustep-core-0.22.0-setup.exe)
gnustep-devel-1.4.0-setup.exe(http://ftp.gnustep.org/pub/gnustep/binaries/windows/gnustep-devel-1.4.0-setup.exe)
gnustep-system-0.22.0-setup.exe(http://ftp.gnustep.org/pub/gnustep/binaries/windows/gnustep-system-0.22.0-setup.exe)
gorm-1.2.8-setup.exe(http://ftp.gnustep.org/pub/gnustep/binaries/windows/gorm-1.2.8-setup.exe)
註意:都要安裝的一個文件夾,如:D:\GNUStep。
三、IDE的配置
好的我們要進入正文了。
首先,啟動Code::Blocks。進入Settings->Compiler and Debugger...,選擇GNU GCC Compiler編譯器,按“Copy”按鈕,並重新命名為“GNUstep MinGW Compiler“並保存。之後進入Other Options 分頁,輸入: -fconstant-string-class=NSConstantString -std=c99
接下來,
連接器設置 Linker stettings
在連接庫(Link Libraries)中添加兩個文件:
D:\GNUstep\GNUstep\System\Library\Libraries\libobjc.dll.a
D:\GNUstep\GNUstep\System\Library\Libraries\libgnustep-base.dll.a
可能你的安裝地址和我的不同,那樣的話可以改一下上述地址。
之後在指定搜索目錄Search directories:Compiler(編譯器)設置為D:\GNUstep\GNUstep\System\Library\Headers
然後,添加Objective-C文件類型支持:進入Settings->Environment...,選擇 Files extension handling 添加*.m, *.mm
再進入 Project->Project tree->Edit file types & categories... ,在Sources, 下面添加 *.m到文件類型列表中,進入 Settings->Editor...,選擇 Syntax highlighting,點擊“Filemasks....”按鈕,在彈出框尾部添加*.m , *.mm到文件類型。
點擊C/C++,在下拉框中選擇Objective C。
四、測試
新建工程,選擇Empty Project。之後新建文件 -> Empty File。保存為main.m(註意後綴名為*.m)。
輸入代碼:
#import <Foundation/Foundation.h> int main (int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"hello world"); [pool drain]; return 0; }
之後構建(Build)並運行(Run)。
如果出現一個顯示“hello world"的窗口,恭喜你,你已經成功搭建了Windows下的Objective-C的集成開發環境。
Windows下配置Objective-C開發環境