window 下的 ios 開發,環境搭建

2021-05-27 10:11:03 字數 2612 閱讀 8737

mac筆記本實在是貴,所以一直沒捨得買,如此一來,就只能在我的windows作業系統上學objective-c了。

安裝gnustep

gnustep windows installer提供了windows平台下的objective-c的模擬開發環境,一共有四個軟體包,其中gnustep system和gnustep core是必裝的,gnustep devel和cairo backend是選裝的。甭管必裝選裝,一次性全安上,免得以後麻煩。

編寫hello, world!

安裝完成後,在開始選單裡的gnustep選項裡執行shell,就能開啟命令列,在這裡就可以使用vi編寫object-c程式了,不過操作起來總有些繁瑣,其實也可以直接在windows裡進入c:\gnustep\home\username目錄,在這裡用你喜歡的工具編寫object-c程式,然後再進入shell裡編譯。

直接給出helloworld.m檔案內容,取自programming in objective-c 2.0一書:

#import

int main (int argc, const char *argv)

第一次編譯:

gcc -o helloworld helloworld.m \

-i /gnustep/system/library/headers/

結果出現錯誤資訊,找不到介面宣告:

helloworld.m: in function `main':

helloworld.m:5: error: cannot find inte***ce declaration for `nxconstantstring'

第三次編譯:

gcc -o helloworld helloworld.m \

-fconstant-string-class=nsconstantstring \

-i /gnustep/system/library/headers/

結果出現錯誤資訊,找不到鏈結庫:

helloworld.m:(.text+0x33): undefined reference to `_objc_get_class'

helloworld.m:(.text+0x45): undefined reference to `_objc_msg_lookup'

helloworld.m:(.text+0x64): undefined reference to `_objc_msg_lookup'

helloworld.m:(.text+0x80): undefined reference to `_nslog'

helloworld.m:(.text+0x93): undefined reference to `_objc_msg_lookup'

helloworld.m:(.text+0xbc): undefined reference to `___objc_exec_class'

helloworld.m:(.data+0x74): undefined reference to `___objc_class_name_nsautoreleasepool'

helloworld.m:(.data+0x78): 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

注意:helloworld.m必須出現在-lobjc和-lgnustep-base的前面,否則會出錯。

此時會出現一些info提示資訊,不過不礙事,終於成功了生成了可執行檔案,執行./helloworld.exe看結果。

快捷方式:

如果每次使用gcc的時候,都要輸入這麼長的命令,無疑是很惱火的事兒,我們可以做乙個快捷方式:

編輯c:\gnustep\bin\gcc.sh的檔案,內容如下:

#!/bin/sh

if [ $# -ne 1 ]; then

echo "usage: $0 name"

exit 1

figcc -g -o $1 $1.m \

-fconstant-string-class=nsconstantstring \

-i /gnustep/system/library/headers/ \

-l /gnustep/system/library/libraries/ \

-lobjc \

-lgnustep-base

exit 0

其中,gcc加入了-g引數,方便gdb除錯,使用時就很方便了,注意別帶副檔名m:

gcc.sh helloworld

window下搭建c開發環境(GNU環境的安裝)

一 在windows平台上安裝gnu環境 windows作業系統不自帶gnu環境,如果需要開發跨平台的c語言程式,那麼需要給windows安裝gnu環境 windows下的兩款gnu環境 mingw和cygwin mingw 完全面向windows平台的gnu環境 環境配置 略 window下配置m...

Window10下Python開發環境的搭建

本章節我們將向大家介紹如何在window10下搭建python開發環境。python可應用於多平台包括 linux 和 mac os x。你可以通過終端視窗輸入 python 命令來檢視本地是否已經安裝python以及python的安裝版本。cmd命令開啟終端,輸入python檢視版本資訊等,如果安...

Window下開發環境安裝和Hello World

ios培訓 我的c語言筆記,期待與您交流 在ios開發中,objective c是在c語言的基礎上的擴充套件,是一種物件導向的程式語言。並依次進行安裝,安裝路徑最好是在根目錄下沒有中文以及空格的資料夾中,我的安裝路徑是d gnustep 2.啟動shell 開啟開始 程式 gnustep shell...