Mac mini 設定 [GSL] [gcc47]

mac mini で gsl を使うためにやったこと。

OpenMPを使う前提で、gcc47 をMacports 経由で入れた。さらに、gsl のオプション -I/usr/local/include を省略するために.bash_profile に加筆をした。

 

(1) gcc47 のインストール

$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix

$ sudo port selfupdate
$ sudo port sync

$ port search gcc
...
gcc47 @4.7.4_3 (lang)
    The GNU compiler collection

...
openmpi-gcc47 @1.7.5_3 (science, parallel, net)
    A High Performance Message Passing Library  →これいつか試そう。

...

などが出てくる。

$ sudo port install gcc47

$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix

$ sudo port select --list gcc
Password:
Available versions for gcc:
    mp-gcc47
    none (active)

$ sudo port select gcc mp-gcc47
Selecting 'mp-gcc47' for 'gcc' succeeded. 'mp-gcc47' is now active.

$ sudo port select --list gcc
Available versions for gcc:
    mp-gcc47 (active)
    none

ターミナル再起動(新しいタブを開く)

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin14/4.7.4/lto-wrapper
Target: x86_64-apple-darwin14
Configured with: /opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/gcc-4.7.4/configure --prefix=/opt/local --build=x86_64-apple-darwin14 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc47 --includedir=/opt/local/include/gcc47 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.7 --with-libiconv-prefix=/opt/local --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.7 --with-gxx-include-dir=/opt/local/include/gcc47/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --disable-ppl-version-check --with-pkgversion='MacPorts gcc47 4.7.4_3'
Thread model: posix
gcc version 4.7.4 (MacPorts gcc47 4.7.4_3)

 

(2) .bash_profile 加筆

$ cd →ホームディレクトリへ移動

$ ls -a .bash_profile

$ vi .bash_profile

としてファイルを開く。ファイルには

MANPATH=/opt/local/man:$MANPATH
とだけ書かれていた。viで以下の文を加筆し、保存し、閉じる。
---ここから---
# Added by *****(me)***** when trying to set the gcc options (02 Jan 2015)
export C_INCLUDE_PATH=/usr/local/include:$C_INCLUDE_PATH

---ここまで---

$ source ~/.bash_profile

として、ターミナルを再起動。

$ echo $C_INCLUDE_PATH
/usr/local/include:

となれば成功。

 

この設定により、gslを用いてコンパイルするとき、

設定前 $ gcc -o hoge hoge.c -I/usr/local/include -lgsl -lgslcblas -lm

  ↓

設定後 $ gcc -o hoge hoge.c -lgsl -lgslcblas -lm

のようにコンパイルオプションが減らせる。

 

ただ、macbook air のときはデフォルトで-I/usr/local/include を省けていたし、airでの環境変数 C_INCLUDE_PATH は空白(何も設定されていない)だった。この辺の理由はよくわからない。