UbuntuにObjective-Cをインストール
ubuntuにObjective-cをインストールしたときの手順
1. Objective-Cのパッケージ「gobjc」をインストールする
# sudo aptitude install gobjc
2. 関連するパッケージをインストールする。
これらをインストールしていないと、ヘッダファイル「Foundation/NSObject.h」をimportしたクラスをコンパイルした時に「error: Foundation/NSObject.h: No such file or directory」というようなエラーが出る。
# sudo aptitude install libgnustep-base-dev # sudo apt-get install gnustep # sudo apt-get install gnustep-devel
3. Objective-Cのサンプルファイルをダウンロードする
$ wget www.otierney.net/files/objc.tar.gz
Objective-Cの簡単な使い方は以下のサイトを参照。
http://www.otierney.net/objective-c.html
4. ダウンロードしたファイルを解凍する
$ tar xzf objc.tar.gz
5. まずはHello Worldを出力するサンプルを動かしてみる
解凍したディレクトリ内にサンプルが色々入っている。helloというディレクトリ下にhello worldを出力するサンプルがある。
$ cd objc/hello/ $ ls main.m output
main.mの内容はこんな感じ。
#import <stdio.h> int main( int argc, const char *argv[] ) { printf( "hello world\n" ); return 0; }
main.mをコンパイルする。
$ gcc -lobjc main.m
ファイルを確認する。実行ファイルが生成されている。
$ ls
a.exe main.m output
生成された実行ファイルを実行する。
$ ./a.exe hello world
- 参考サイト
http://d.hatena.ne.jp/ykot/20100625/1277440933
http://l-w-i.net/t/ubuntu/objc_001.txt
http://d.hatena.ne.jp/tomute/20090112/1231809116