Objective-C開發(fā)之CodeBlocks實例操作
Objective-C開發(fā)之CodeBlocks實例操作的內(nèi)容是本文要介紹的內(nèi)容,主要講述了CodeBlocks相關(guān)的內(nèi)容,先來看詳細內(nèi)容。
1. 首先安裝Objective-C編譯器
GNUstep Windows Installer提供了Windows平臺下的Objective-C的模擬開發(fā)環(huán)境,一共有四個軟件包,其中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:GNUstepmingwbin
3. 創(chuàng)建Objective-C工程
創(chuàng)建一個Console的C工程,將main.c刪除,新建main.m文件,內(nèi)容如下:
- #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的內(nèi)容改為CC
4. 設(shè)置編譯選項
(1)方法一
右擊將創(chuàng)建的工程,選擇Build options…,Selected compiler編譯器選擇GNUstep MinGW Compiler, 選擇Compiler settings>Other options中填入-fconstant-string-class=NSConstantString
選擇Linker settings選項卡,點擊Add,增加如下兩行內(nèi)容:
- C:/GNUstep/GNUstep/System/Library/Libraries/libobjc.dll.a
- C:/GNUstep/GNUstep/System/Library/Libraries/libgnustep-base.dll.a
選擇Search directories>Compiler,點擊Add,增加如下內(nèi)容:
- C:/GNUstep/GNUstep/System/Library/Headers
(2)方法二
右擊將創(chuàng)建的工程,選擇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文件類型高亮及編輯器關(guān)聯(lián)
(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即可。
小結(jié):Objective-C開發(fā)之CodeBlocks實例操作的內(nèi)容介紹完了,希望本文對你有所幫助!