【Koding.com】objective-cを勉強するために、練習環境を構築

## 背景
* 初心者として、Objective-C言語を勉強する(iOSアプリ開発じゃない)
* 各場所に勉強できるようにしたい
* アップルPCがなしw

## 参照
* [Ubuntu で Objective-C のコンパイル](https://linux2.g.hatena.ne.jp/lnznt/20131011/1381446718)
* [koding](https://koding.com)(ブラウザでubuntu上に軽く開発できるサイト)
* [UbuntuにCLANGをインストールする](http://krakenbeal.blogspot.jp/2012/11/ubuntuclang.html)
* [[Objective-C][Vim] vim で *.m を作ると最初に matlab だと認識されてしまう](http://d.hatena.ne.jp/eagletmt/20090226/1235648414)

## 環境構築
* kodingにログインして、https://koding.com/Terminal でterminalを使えるように
* gccがインストールされて、確認のみ

```
$ gcc --version
gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
......
```

* Objective-C のコンパイラを入れる

 * ```
$ sudo apt-get install gobjc
```

 * 詳しくは、「メモ」に参照してください

* SingleCompileのインストール
 * 参照： [C++勉強のために、koding上に簡単的に環境構築する](http://qiita.com/alingogo@github/items/e5db406bfe24c463e2ae)

--

* 「Hello World」プログラム

```objc
#import <objc/Object.h>
 
int main()
{
  printf("hello world!\n");
  return;
}
```

* 「:SCCompileRun」を実行したけど、「SingleCompile: No compiler is detected on your system!」エラーが表示された
* ファイルを保存して、再オープンして、「:SCCompileRun」を実行してOK（原因がわからんw）
* http://www.topbug.net/SingleCompile/ を読んで、clang (the Clang C and Objective-C compiler)をサポートしている

--

* Clangを入れる

 * ```
$ sudo apt-get install clang
```

 * 詳しくは、「メモ」に参照してください

* 確認

```bash
$ clang -v
Ubuntu clang version 3.2-1~exp9ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
Target: x86_64-pc-linux-gnu
Thread model: posix
```

* 「:SCCompileRun」を実行したけど、「SingleCompile: No compiler is detected on your system!」エラーが表示された
* ファイルを保存して、再オープンして、「:SCCompileRun」を実行してOK
* なんで、clangも？

--
* [vim で *.m を作ると最初に matlab だと認識されてしまう](http://d.hatena.ne.jp/eagletmt/20090226/1235648414)
* h.mファイルに、「:set filetype」を実行すると、以下の情報が出た

 * ```
filetype=matlab
```

* matlabを普段使っていないので、g:filetype_mを参照して、存在する場合にobjcとして使う
 * ~/.vimrcに、以下を追加

 * ```
let g:filetype_m = 'objc'
```

* もう一度、h.mファイルに、「:set filetype」を実行すると、以下の情報が出た

 * ```
filetype=objc
```

*  「:SCCompileRun」を実行してOK

----

----

----

## メモ

```bash
$ sudo apt-get install gobjc
[sudo] password for happyinjap:         
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  gobjc-4.7 libobjc-4.7-dev libobjc4
Suggested packages:
  gobjc-multilib gobjc-4.7-multilib gcc-4.7-doc libobjc4-dbg
The following NEW packages will be installed:
  gobjc gobjc-4.7 libobjc-4.7-dev libobjc4
0 upgraded, 4 newly installed, 0 to remove and 25 not upgraded.
Need to get 6,140 kB of archives.
After this operation, 15.9 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://apt-mirror.in.koding.com/ubuntu/ raring/main libobjc4 amd64 4.7.3-1ubuntu1 [156 kB]
Get:2 http://apt-mirror.in.koding.com/ubuntu/ raring/main libobjc-4.7-dev amd64 4.7.3-1ubuntu1 [73
0 kB]
Get:3 http://apt-mirror.in.koding.com/ubuntu/ raring/main gobjc-4.7 amd64 4.7.3-1ubuntu1 [5,253 kB
]
Get:4 http://apt-mirror.in.koding.com/ubuntu/ raring/main gobjc amd64 4:4.7.3-1ubuntu10 [894 B]
Fetched 6,140 kB in 0s (23.4 MB/s)
Selecting previously unselected package libobjc4:amd64.
(Reading database ... 103955 files and directories currently installed.)
Unpacking libobjc4:amd64 (from .../libobjc4_4.7.3-1ubuntu1_amd64.deb) ...
Selecting previously unselected package libobjc-4.7-dev:amd64.
Unpacking libobjc-4.7-dev:amd64 (from .../libobjc-4.7-dev_4.7.3-1ubuntu1_amd64.deb) ...
Selecting previously unselected package gobjc-4.7.
Unpacking gobjc-4.7 (from .../gobjc-4.7_4.7.3-1ubuntu1_amd64.deb) ...
Selecting previously unselected package gobjc.
Unpacking gobjc (from .../gobjc_4%3a4.7.3-1ubuntu10_amd64.deb) ...
Setting up libobjc4:amd64 (4.7.3-1ubuntu1) ...
Setting up libobjc-4.7-dev:amd64 (4.7.3-1ubuntu1) ...
Setting up gobjc-4.7 (4.7.3-1ubuntu1) ...
Setting up gobjc (4:4.7.3-1ubuntu10) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
```

```bash
$ sudo apt-get install clang
[sudo] password for happyinjap:         
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  binfmt-support clang-3.2 compiler-rt libclang-common-dev llvm-3.2 llvm-3.2-dev
  llvm-3.2-runtime
Suggested packages:
  llvm-3.2-doc
The following NEW packages will be installed:
  binfmt-support clang clang-3.2 compiler-rt libclang-common-dev llvm-3.2 llvm-3.2-dev
  llvm-3.2-runtime
0 upgraded, 8 newly installed, 0 to remove and 25 not upgraded.
Need to get 26.6 MB of archives.
After this operation, 89.8 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://apt-mirror.in.koding.com/ubuntu/ raring/main binfmt-support amd64 2.0.13 [79.7 kB]
Get:2 http://apt-mirror.in.koding.com/ubuntu/ raring/universe libclang-common-dev amd64 3.2-1~exp9
ubuntu1 [300 kB]
Get:3 http://apt-mirror.in.koding.com/ubuntu/ raring/universe compiler-rt amd64 3.2-1~exp9ubuntu1 
[310 kB]
Get:4 http://apt-mirror.in.koding.com/ubuntu/ raring/universe clang-3.2 amd64 3.2-1~exp9ubuntu1 [1
0.1 MB]
Get:5 http://apt-mirror.in.koding.com/ubuntu/ raring/universe clang all 3.2-1~exp9ubuntu1 [3,106 B
]
Get:6 http://apt-mirror.in.koding.com/ubuntu/ raring/main llvm-3.2-runtime amd64 3.2-2ubuntu5 [30.
7 kB]
Get:7 http://apt-mirror.in.koding.com/ubuntu/ raring/main llvm-3.2 amd64 3.2-2ubuntu5 [1,436 kB]
Get:8 http://apt-mirror.in.koding.com/ubuntu/ raring/main llvm-3.2-dev amd64 3.2-2ubuntu5 [14.4 MB
]
Fetched 26.6 MB in 1s (16.3 MB/s)       
Selecting previously unselected package binfmt-support.
(Reading database ... 103983 files and directories currently installed.)
Unpacking binfmt-support (from .../binfmt-support_2.0.13_amd64.deb) ...
Selecting previously unselected package libclang-common-dev.
Unpacking libclang-common-dev (from .../libclang-common-dev_3.2-1~exp9ubuntu1_amd64.deb) ...
Selecting previously unselected package compiler-rt.
Unpacking compiler-rt (from .../compiler-rt_3.2-1~exp9ubuntu1_amd64.deb) ...
Selecting previously unselected package clang-3.2.
Unpacking clang-3.2 (from .../clang-3.2_3.2-1~exp9ubuntu1_amd64.deb) ...
Selecting previously unselected package clang.
Unpacking clang (from .../clang_3.2-1~exp9ubuntu1_all.deb) ...
Selecting previously unselected package llvm-3.2-runtime.
Unpacking llvm-3.2-runtime (from .../llvm-3.2-runtime_3.2-2ubuntu5_amd64.deb) ...
Selecting previously unselected package llvm-3.2.
Unpacking llvm-3.2 (from .../llvm-3.2_3.2-2ubuntu5_amd64.deb) ...
Selecting previously unselected package llvm-3.2-dev.
Unpacking llvm-3.2-dev (from .../llvm-3.2-dev_3.2-2ubuntu5_amd64.deb) ...
Processing triggers for man-db ...
Processing triggers for ureadahead ...
Setting up binfmt-support (2.0.13) ...
update-binfmts: warning: Couldn't load the binfmt_misc module.
update-binfmts: warning: Couldn't load the binfmt_misc module.
update-binfmts: warning: Couldn't load the binfmt_misc module.
update-binfmts: warning: Couldn't load the binfmt_misc module.
initctl: Unknown job: binfmt-support
Setting up libclang-common-dev (3.2-1~exp9ubuntu1) ...
Setting up compiler-rt (3.2-1~exp9ubuntu1) ...
Setting up clang-3.2 (3.2-1~exp9ubuntu1) ...
Setting up clang (3.2-1~exp9ubuntu1) ...
Processing triggers for ureadahead ...
Setting up llvm-3.2-runtime (3.2-2ubuntu5) ...
update-binfmts: warning: Couldn't load the binfmt_misc module.
Setting up llvm-3.2 (3.2-2ubuntu5) ...
Setting up llvm-3.2-dev (3.2-2ubuntu5) ...
```