轉自:http://kingj.iteye.com/blog/1558869
<1>
Objective-C是蘋果軟體的程式設計語言,想要上機學習、調試,有一個整合式開發環境(IDE)方便很多。有三類方法搭建Objective-C的整合式開發環境:
<!--[if !supportLists]-->1) <!--[endif]-->使用蘋果的平台,整合式開發環境使用Xcode。但如果沒有蘋果平台,想在Windows環境下學習Objective-C,可以採用以下兩種方法:
<!--[if !supportLists]-->2) <!--[endif]-->在Windows環境下設定一個蘋果虛擬機器,但這對個人電腦的效能要求較高,不是所有個人電腦都可以,而且虛擬機器的運行速度也較慢;
<!--[if !supportLists]-->3) <!--[endif]-->採用Codeblocks IDE開發環境,對其進行配置,搭建成支援Object-C的編譯、調試、啟動並執行整合式開發環境。這種方法對個人電腦的效能幾乎沒有要求,可以快速構建,本文介紹的是這一種方法。
1、安裝Object-C的編譯器
Objective-C的編譯器有很多,本文介紹使用GnuStep,網址是http://www.gnustep.org/experience/Windows.html,從這裡可以下載Windows版本的gcc編譯器:
進入下載頁面,下載上面3個軟體包,進行安裝,例如安裝到D:\GNUstep。關於這3個軟體包的作用,可以在網上查詢,不再贅述。
2、安裝Object-C的整合式開發環境
我們選擇用CodeBlocks IDE作為Objective-C的整合式開發環境,是:http://www.codeblocks.org/。
3、開發環境配置
通過對Code blocks的配置,一步步完成Objective-C開發環境的搭建。CodeBlocks,可以看見這樣的畫面:
第一步:配置編譯器
進入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下面:
libgnustep-base.dll.a
libobjc.dll.a
第三步:指定搜尋目錄Search directories(需要預先安裝好GNUstep)
<!--[if !supportLists]-->1) <!--[endif]-->Compiler(編譯器)設定為D:\GNUstep\GNUstep\System\Library\Headers;
2) Linker(連接器)設定為D:\GNUstep\GNUstep\System\Library\Libraries;
第四步:添加Objective-C檔案類型支援
<!--[if !supportLists]--> 1) <!--[endif]-->進入Settings->Environment...,選擇 Files extension handling 添加*.m。
2) 進入 Project->Project tree->Edit file types & categories... ,在Sources, 下面添加 *.m到檔案類型列表中。
3) 進入 Settings->Editor...,選擇 Syntax highlighting,點擊“Filemasks....”按鈕,在彈出框尾部添加*.m 到檔案類型。
4) 點擊“Keywords...”按鈕 (緊靠Filemasks...按鈕) 添加下面Object-C的關鍵字到Edit Keywords列表中。。
@interface @implementation @end @class @selector @protocol @public @protected @private id BOOL YES NO SEL nil NULL self @protocol
|
<!--[if !supportLists]-->4. <!--[endif]-->代碼測試
上述開發環境配置完成後,就可以開始代碼測試了。
首先,建立一個工程,選擇File->New->Project…,會出現一個工程類型視窗,選擇Console Application,然後按照工程建立指引,建立一個mytest的工程,並將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;
}
之後再開始編譯運行:Buid –> Run… 如果出現以下視窗,恭喜你,你已經成功的搭建了Windows下的Objective-C的整合式開發環境。
之後再開始編譯運行:Buid –> Run… 如果出現以下視窗,恭喜你,你已經成功的搭建了Windows下的Objective-C的整合式開發環境。
如果順利編譯通過並運行,那麼恭喜object-c的windows開發環境已經配置好了,如果你想瞭解並運行cocoa架構的話
還需要對codeblocks進行下一步配置。
聲明:轉自:http://www.jxva.com/blog/201112/208.html<2>
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:GNUstepmingwbin3.建立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的內容改為CC4.設定編譯選項(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.aC:/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即可更多參考資訊:http://wiki.codeblocks.org/index.php?title=Installing_Objective-C_Compiler