Windows下安装Object C开发环境,及Hello Word(转)
Windows下安裝Object C開(kāi)發(fā)環(huán)境,及Hello Word
最近想學(xué)習(xí)iphone開(kāi)發(fā),但是由于沒(méi)有c基礎(chǔ),只有java基礎(chǔ)。所以先從基礎(chǔ)學(xué)習(xí),首先是搭建環(huán)境,目前手頭沒(méi)有mac機(jī)子,只能先在windows下學(xué)習(xí)基本語(yǔ)法。還好找到了GNUset,可以利用GNUstep在windows下模擬object c開(kāi)發(fā)環(huán)境。
官方網(wǎng)址:http://www.gnustep.org/
安裝:
GNUstep Windows Installer提供了Windows平臺(tái)下的Objective-C的模擬開(kāi)發(fā)環(huán)境,一共有四個(gè)軟件包,其中GNUstep System和GNUstep Core是必裝的,GNUstep Devel和Cairo Backend是選裝的。甭管必裝選裝,一次性全安上,免得以后麻煩。
編寫(xiě)HelloWord
幾乎所有的開(kāi)發(fā)環(huán)境都是以HelloWord開(kāi)始,在這里我們先編寫(xiě)HelloWord.
安裝完成后,在開(kāi)始菜單里的GNUstep選項(xiàng)里執(zhí)行shell,就能打開(kāi)命令行,在這里就可以使用vi編寫(xiě)Object-C程序了,不過(guò)操作起來(lái)總有些繁瑣,其實(shí)也可以直接在Windows里進(jìn)入C:\GNUstep\home\username目錄,在這里用你喜歡的工具編寫(xiě)Object-C程序,然后再進(jìn)入shell里編譯。?
直接給出helloworld.m文件內(nèi)容,取自Programming in Objective-C 2.0一書(shū):
#import <Foundation/Foundation.h>?
int main (int argc, const char *argv[]) {?
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];?
NSLog(@"Hello World!");?
[pool drain];?
return 0;?
}
第一次編譯:
gcc -o helloworld helloworld.m
結(jié)果出現(xiàn)錯(cuò)誤信息,找不到頭文件:
helloworld.m:1:34: Foundation/Foundation.h: No such file or directory?
helloworld.m: In function `main’:?
helloworld.m:4: error: `NSAutoreleasePool’ undeclared (first use in this function)?
helloworld.m:4: error: (Each undeclared identifier is reported only once?
helloworld.m:4: error: for each function it appears in.)?
helloworld.m:4: error: `pool’ undeclared (first use in this function)?
helloworld.m:5: error: cannot find interface declaration for `NXConstantString’
?
第二次編譯:
gcc -o helloworld helloworld.m \?
-I /GNUstep/System/Library/Headers/
結(jié)果出現(xiàn)錯(cuò)誤信息,找不到接口聲明:
helloworld.m: In function `main’:?
helloworld.m:5: error: cannot find interface declaration for `NXConstantString’
第三次編譯:
?
gcc -o helloworld helloworld.m \?
-fconstant-string-class=NSConstantString \?
-I /GNUstep/System/Library/Headers/
?
結(jié)果出現(xiàn)錯(cuò)誤信息,找不到鏈接庫(kù):
helloworld.m:(.text+0×33): undefined reference to `_objc_get_class’?
helloworld.m:(.text+0×45): undefined reference to `_objc_msg_lookup’?
helloworld.m:(.text+0×64): undefined reference to `_objc_msg_lookup’?
helloworld.m:(.text+0×80): undefined reference to `_NSLog’?
helloworld.m:(.text+0×93): undefined reference to `_objc_msg_lookup’?
helloworld.m:(.text+0xbc): undefined reference to `___objc_exec_class’?
helloworld.m:(.data+0×74): undefined reference to `___objc_class_name_NSAutoreleasePool’?
helloworld.m:(.data+0×78): undefined reference to `___objc_class_name_NSConstantString’?
collect2: ld returned 1 exit status
第四次編譯:
?
gcc -o helloworld helloworld.m \?
-fconstant-string-class=NSConstantString \?
-I /GNUstep/System/Library/Headers/ \?
-L /GNUstep/System/Library/Libraries/ \?
-lobjc \?
-lgnustep-base
?執(zhí)行上面的路徑還是會(huì)提示找不到Foundation/Foundation.h 需要加上絕對(duì)路徑,命令:
gcc -o helloworld helloworld.m -fconstant-string-class=NSConstantString -I C:\GNUstep\GNUstep\System\Library\Headers\ -L C:\GNUstep\GNUstep\System\Library\Libraries\ -lobjc -lgnustep-base
?
注意:helloworld.m必須出現(xiàn)在-lobjc和-lgnustep-base的前面,否則會(huì)出錯(cuò)。?
此時(shí)會(huì)出現(xiàn)一些info提示信息,不過(guò)不礙事,終于成功了生成了可執(zhí)行文件,執(zhí)行看結(jié)果。
./helloworld.exe ? ? windows命令行:helloworld
結(jié)果是:
注意,可以利用粘貼復(fù)制命令:Ctrl+p
轉(zhuǎn)載于:https://www.cnblogs.com/antyi/p/3271956.html
總結(jié)
以上是生活随笔為你收集整理的Windows下安装Object C开发环境,及Hello Word(转)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux学习笔记之--vim 程序编辑
- 下一篇: 应用系统开发思想的变迁