使用Codeblock搭建Windows下Objec-c學習環境

來源:互聯網
上載者:User

標籤:

  學習Object-c如果使用的是Windows,一般推薦使用虛擬機器,但是太重量級了,先要下載OS-X,又要下載x-code。這裡推薦一種比較簡便的方式,使用code-block來搭建簡易的Object-c學習環境,是:http://www.codblocks.org/。

  Objective-C的編譯器有很多,這裡使用GnuStep,網址是http://www.gnustep.org/experience/Windows.html,從這裡可以下載Windows版本的gcc編譯器,共有四個軟體包,其中GNUstep System和GNUstep Core是必裝的,GNUstep Devel和Cairo Backend是選裝的(用迅雷拖要快點)。

  下載並安裝好Code-block 和 GnuStep 之後,對Code-block進行配置。

  開啟Code::Blocks,點擊菜單Settings>Compiler and debugger>Global compiler settings在Selected compiler下拉框下面點擊Copy, 在快顯視窗中填入: GNUstep MinGW Compiler之後,點擊Toolchain executables選項卡,將Compiler’s installation directory選擇為C:\GNUstep,如:  

  接下來找到Other Options 選項卡,寫入-fconstant-string-class=NSConstantString -std=c99 :

 

    接下來設定靜態連結庫,在Link settings 中進行添加,需要添加的.a檔案在:C:\GNUstep\GNUstep\System\Library\Libraries: libgnustep-base.dll.a 和 libobjc.dll.a,

    

 

     接下來在Search irectories 中的Compiler選項卡中增加:C:\GNUstep\GNUstep\System\Library\Headers;在Linker選項卡中增加:C:\GNUstep\GNUstep\System\Library\Libraries。這裡就不了。

       進入Settings->Environment...,選擇Files extension handling 添加*.m;進入 Project->Projecttree->Edit file types & categories... ,在Sources, 下面添加*.m到檔案類型列表中。

       進入Settings->Editor...,選擇 Syntaxhighlighting,點擊“Filemasks....”按鈕,在彈出框尾部添加*.m 到檔案類型;點擊“Keywords...”按鈕 (緊靠Filemasks...按鈕) 添加下面Object-C的關鍵字到EditKeywords列表中:@interface @implementation @end  @class @selector @protocol @public @protected @private id BOOL YES NO SEL nil  NULL self。

     

     最後進行測試,選擇File->New->Project…,會出現一個工程類型視窗,選擇Console Application,然後按照工程建立指引,建立一個mTest的工程,並將main.c的檔案更名為main.m,寫入代碼:

#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];    NSDate *now = [NSDate date];    NSLog(@"This NSDate object lives at %p", now);    NSLog(@"The date is %@", now);    [pool drain];    return 0;}

  編譯運行上述代碼,結果如下:

  

 

使用Codeblock搭建Windows下Objec-c學習環境

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.