差不多該學學 Objective-C 了,手邊也有 iphone 及相關的環境可開發,剩下只有懶散的心情要整頓。至於什麼是 Objective-C ,可以先看看維基百科的介紹,我覺得還滿詳盡的,甚至英文版還有介紹從 C/C++ 跨到 Objective-C 的範例程式,真的就乾心哩,看程式比看英文快上十倍啊。
跟 iphone 開發相關的網頁介紹:
- Introduction to The Objective-C Programming Language
- Objective-C Runtime Programming Guide
- Objective-C Runtime Reference
其他相關的教學
接著,就只剩環境架設的部分,
在 Ubuntu 9.10 最簡化版:
- 安裝相關套件
- # sudo apt-get install gnustep-devel
- The following extra packages will be installed:
gnustep-back-common gnustep-back0.16 gnustep-back0.16-art gnustep-base-doc gnustep-core-devel gnustep-core-doc gnustep-gpbs gnustep-gui-common
gnustep-gui-doc gnustep-gui-runtime gnustep-make-doc gorm.app libaspell-dev libaudiofile-dev libgif-dev libgnustep-gui-dev libgnustep-gui0.16
libjpeg62-dev libpng12-dev librenaissance0 librenaissance0-dev libtiff4-dev libtiffxx0c2 projectcenter.app projectmanager.app zlib1g-dev
- 安裝完就能用 gcc 進行編譯囉
- # gcc -lgnustep-base -lpthread -lobjc -lm -I/usr/local/include/GNUstep -I/usr/include/GNUstep source.m -o source_run
- 參考資料
- [ubuntu] how do I compile objective C on ubuntu - Ubuntu Forums
- 文章建議安裝: build-essential s, gobjc, gnustep-common, gnustep-devel, and libgnustep-base-dev.
使用 Makefile 的教學:
- 建立 GNUmakefile
- GNUSTEP_MAKEFILES = /usr/share/GNUstep/Makefiles/
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = LogTest
LogTest_OBJC_FILES = source.m
include $(GNUSTEP_MAKEFILES)/tool.make - 最上頭那段是我自己加的,網路上大部分的文件都是使用 shell 來設置環境變數
- C shell
- # source <GNUstep root>/System/Library/Makefiles/GNUstep.csh
- Bourne shell
- # . <GNUstep root>/System/Library/Makefiles/GNUstep.sh
- C shell
- GNUSTEP_MAKEFILES = /usr/share/GNUstep/Makefiles/
- 建立 source.m
- #include <stdio.h>
/*
* The next #include line is generally present in all Objective-C
* source files that use GNUstep. The Foundation.h header file
* includes all the other standard header files you need.
*/
#include <Foundation/Foundation.h>
/*
* Declare the Test class that implements the class method (classStringValue).
*/
@interface Test
+ (const char *) classStringValue;
@end
/*
* Define the Test class and the class method (classStringValue).
*/
@implementation Test
+ (const char *) classStringValue;
{
return "This is the string value of the Test class";
}
@end
/*
* The main() function: pass a message to the Test class
* and print the returned string.
*/
int main(void)
{
printf("%s\n", [Test classStringValue]);
return 0;
}
- #include <stdio.h>
- 編譯與測試
- # mkdir test ; cd test ;
- # vim GNUmakefile (內容如上)
- # vim source.m (內容如上)
- # make ;
- # ./obj/LogTest
- 輸出結果:This is the string value of the Test class
- 參考資料
- Objective-C GNUstep Base Programming Manual: Introduction - 1.5 Building Your First Objective-C Program
- Ubuntu 下 Objective-C 开发环境
- Learn Objective-C on Ubuntu