El Capitan でFORTRAN環境を作るため最新のgccを入れた

MacPortsgccを入れる。

gccのサイト
http://gcc.gnu.org/wiki/GFortranBinaries#MacOS
を見ると、El Capitanにはgfortran 5.2だという。MacPortsGCCを入れればgfortranも入るっぽいことが書いてあるように見える。

これはMacPortsで扱えるのか?ということでMacPortsのサイトでGCCパッケージを探してみる。
https://www.macports.org/ports.php?by=name&substr=gcc

すると、今日現在、(β版ではgcc6が出ているが)最新版はgcc5(gcc5 5.3.0)のようである。

そこで、ターミナルでportsを探す。

$ port search gcc5
gcc5 @5.3.0 (lang)
    The GNU compiler collection

mpich-devel-gcc5 @3.2_3 (science, parallel, net)
    Message Passing Interface (MPI) Library

mpich-gcc5 @3.2_3 (science, parallel, net)
    Message Passing Interface (MPI) Library

openmpi-devel-gcc5 @1.10.99_36275 (science, parallel, net)
    A High Performance Message Passing Library

openmpi-gcc5 @1.10.2 (science, parallel, net)
    A High Performance Message Passing Library

Found 5 ports.

あったあった。たぶん1つめのやつでいいんだろう。

でも元々gccって入ってるように見えるんだよなぁ…

$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.29)
Target: x86_64-apple-darwin15.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

まぁ、gcc5を入れてみよう

20分くらいかかっていろいろ入った模様。最後に気になるコメントが表示されたのでメモ。

To make this the default Python or Python 2 (i.e., the version run by the 'python' or 'python2' commands), run one or both of:

    sudo port select --set python python27
    sudo port select --set python2 python27

さてgfortranは入ったのか?gfとだけ打ってtabキーを押すと

$ gfortran-mp-5

と補完された。ナンダコレハ

とりあえずhelloworld.f95が置いてあるデスクトップに移ってこれでコンパイルを試みる

$ gfortran-mp-5 helloworld.f95 
$ a.out
-bash: a.out: command not found

あっ

$ ./a.out
 hello, world.

通った!!