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

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

編譯其他選項(xiàng)錄入:-fconstant-string-class=NSConstantString -std=c99

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


設(shè)置編譯器、連接器的搜索目錄

4、配置語(yǔ)法、文件類型,關(guān)鍵字等
添加文件類型支持
1) 進(jìn)入Settings->Environment...
2) 選擇 Files extension handling 添加*.m
3) 進(jìn)入 Project->Project tree->Edit file types & categories...
4) 在Sources, 下面添加 *.m到文件類型列表中.
添加語(yǔ)法高亮支持
1) 進(jìn)入 Settings->Editor...
2) 選擇 Syntax highlighting 進(jìn)入Filemasks.... 添加*.m 到文件類型列表中.
3) 進(jìn)入 Keywords... (緊靠Filemasks...) 添加下面的關(guān)鍵字到列表中
@interface @implementation @end @class @selector @protocol @public @protected @private id BOOL YES NO SEL nil NULL self |
語(yǔ)法高亮中,加入*.m擴(kuò)展名
5、代碼測(cè)試
新建一個(gè)工程,修改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;
}
編譯運(yùn)行效果如下:
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. |