1、安裝編譯器
Objective-C的編譯器有很多,其中LLVM屬于從GCC發(fā)展出來的,主要使用在蘋果的平臺中,GNU可以使用GnuStep,網(wǎng)址是http://wwwmain.gnustep.org/,從這里可以下載Windows版本的gcc編譯器,配合codeblocks可以編譯調(diào)試object c程序。

進入下載頁面,下載上面3個軟件包,安裝,例如安裝到D:\GNUstep,
2、安裝CodeBlocks IDE環(huán)境
下載地址:http://www.codeblocks.org/
3、配置編譯器
安裝好codeblocks之后,進入Settings->Compiler and debugger...,選擇GNU GCC Compiler編譯器,復制重新命名為“GNUstep MinGW Compiler“配置

編譯其他選項錄入:-fconstant-string-class=NSConstantString -std=c99

同時指定搜索目錄:
》編譯器的搜索目錄是D:\GNUstep\GNUstep\System\Library\Headers
》linker的搜索目錄設置為D:\GNUstep\GNUstep\System\Library\Libraries,同時設置linker的參數(shù):-lobjc -lgnustep-base
或者可以在linker選項中加入D:\GNUstep\GNUstep\System\Library\Libraries下面的2個文件libgnustep-base.dll.a,libobjc.dll.a


設置編譯器、連接器的搜索目錄

4、配置語法、文件類型,關鍵字等
添加文件類型支持
1) 進入Settings->Environment...
2) 選擇 Files extension handling 添加*.m
3) 進入 Project->Project tree->Edit file types & categories...
4) 在Sources, 下面添加 *.m到文件類型列表中.
添加語法高亮支持
1) 進入 Settings->Editor...
2) 選擇 Syntax highlighting 進入Filemasks.... 添加*.m 到文件類型列表中.
3) 進入 Keywords... (緊靠Filemasks...) 添加下面的關鍵字到列表中
@interface @implementation @end @class @selector @protocol @public @protected @private id BOOL YES NO SEL nil NULL self |
語法高亮中,加入*.m擴展名
5、代碼測試
新建一個工程,修改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;
}
編譯運行效果如下:
2012-03-07 17:33:49.711 objc1[6080] hello world
Process returned 0 (0x0) execution time : 0.220 s Press any key to continue. |