Amazon Linux上で、Objective-Cの環境を作った。
いろいろ試行錯誤したのでやったことを覚え書きしておく。

下記のページをメチャクチャ参考にさせていただいた。
https://qiita.com/ryochin/items/77100d42da4f8cfc8b8f

手順

# いろいろインストール
$ sudo yum install -y gcc-objc \
libffi libffi-devel \
libxml2 libxml2-devel libxslt libxslt-devel gnutls gnutls-devel libicu libicu-devel

# 下記コマンドを実行して、gcc44以外のバージョンが入っているようなら、gcc44に変更しておく
$ sudo update-alternatives --config gcc

# gnustep-make、gnustep-baseをインストール
# 下記のURLにブラウザでアクセスすると、gnustep-make、gnustep-baseのバージョン一覧を見られる。とりあえず現時点での最新版を使った。
# ftp://ftp.gnustep.org/pub/gnustep/core

$ wget ftp://ftp.gnustep.org/pub/gnustep/core/gnustep-make-2.7.0.tar.gz
$ tar -zxvf gnustep-make-2.7.0.tar.gz
$ cd gnustep-make-2.7.0
$ ./configure
$ sudo make install

$ sudo ln -s /usr/local/bin/gnustep-config /usr/bin/
$ wget ftp://ftp.gnustep.org/pub/gnustep/core/gnustep-base-1.25.1.tar.gz
$ tar -zxvf gnustep-base-1.25.1.tar.gz
$ cd gnustep-base-1.25.1
$ ./configure
$ make
$ sudo make install

# hello worldのコードを用意する。
# hello worldのコードは下記ページのものを参考にさせていただいた。
# http://linuxserver.jp/%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0/objective-c/hello-world-from-objc
$ vim main.m

# このままだとlibgnustep-base.so.1.25をうまく探せなかったので、ld.so.confを編集しておく。
# 下記で適切なパスを探す
$ find /usr -name "*libgnustep-base*"
# 自分の環境だと結果は下記のような感じだった。
# /usr/local/lib/libgnustep-base.so.1.25.1
# /usr/local/lib/libgnustep-base.so
# /usr/local/lib/libgnustep-base.so.1.25
########
# 下記のファイルに、パスへの行を追加。自分の環境だと下記の行を追加した。
# /usr/local/lib/
$ sudo vim /etc/ld.so.conf
# 反映
$ sudo ldconfig

$ gcc -o main main.m -lobjc -lgnustep-base
$ ./main
Hello World.

遭遇したエラー

gcc-objcを入れずにコンパイル

$ gcc -o main main.m
gcc: error: main.m: Objective-C compiler not installed on this system

作業していた時のハマり方としては、「gccのバージョンが4.8だったんだけども、gcc44-objcをインストールしていたせいで、gcc-objcがないことになってた」という感じだった。
sudo update-alternatives --config gccでバージョンを変更した。
gcc44 -o main main.mでもこのエラーは回避できるけど、update-alternativesしておくと、今回の作業のうちgnustep-baseのインストールの時に出てしまうエラーも回避できるので一石二鳥。

gnustepを入れずにコンパイル

$ gcc44 -o main main.m
main.m:1:34: error: Foundation/Foundation.h: No such file or directory

gnustepを入れれば解消する。

libgnustep-base.so.1.25が見つからない

$ gcc44 -o main main.m -lobjc -lgnustep-base
$ ./main
./main: error while loading shared libraries: libgnustep-base.so.1.25: cannot open shared object file: No such file or directory

$ ldd ./main
        linux-vdso.so.1 =>  (0x00007ffc9c51b000)
        libobjc.so.2 => /usr/lib64/libobjc.so.2 (0x00007fc396df9000)
        libgnustep-base.so.1.25 => not found
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc396be3000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fc39681f000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fc397015000)

「手順」に書いた、「ld.so.confを編集しておく」のところの流れで対処できた。
対処方法については下記ページを参考にさせていただいた。
http://jsapachehtml.hatenablog.com/entry/2015/01/09/210255
http://www.8wave.net/ldconfig.html

学んだこと

インストールしたパッケージを確認

$ yum list | grep ffi
libffi.x86_64                        3.0.13-16.5.amzn1             installed
...

パッケージのパスを確認

https://stackoverflow.com/questions/1766380/determining-the-path-that-a-yum-package-installed-to

$ rpm -ql libffi
/usr/lib64/libffi.so.6
/usr/lib64/libffi.so.6.0.1
/usr/share/doc/libffi-3.0.13
/usr/share/doc/libffi-3.0.13/LICENSE
/usr/share/doc/libffi-3.0.13/README

ファイルの所在を確認

$ ls /usr/lib64 -R | grep ffi

$ ls /usr/lib -R | grep ffi

$ find /usr -name "*libgnustep-base*"

共有ライブラリを確認

$ sudo ldconfig -v

共有ライブラリにパスを通す

# ライブラリ探す
$ find /usr -name "*libgnustep-base*"

# 新しい行にパスを記述
$ sudo vim /etc/ld.so.conf

# 反映
$ sudo ldconfig