LoginSignup
2
2

More than 5 years have passed since last update.

OSXにFortran Compilerのf2c,f77をインストールする

Posted at

はじめに

Mac OS XでFortranを使う場合,大体はgfortranをインストールすれば事足ります.gfortranのインストールはMacPortsが使えるため,非常に簡単です.しかし今回f2cが必要になり,少しインストールに戸惑ったので備忘録.

環境

  • OSX 10.10.3

インストール手順

調べていたところ,まさにFortran Compiler Installation Instructions for OS Xというドンピシャな記事があり,しかもインストールのためのシェルスクリプトも記載してあったので,これを試しました.


#! /bin/csh
setenv INSTALL /usr/local
curl "http://netlib.sandia.gov/cgi-bin/netlib/netlibfiles.tar?filename=netlib/f2c" -o "f2c.tar"
tar -xvf f2c.tar
gunzip -rf f2c/*
cd f2c
mkdir libf2c
mv libf2c.zip libf2c
cd libf2c
unzip libf2c.zip
cp makefile.u Makefile
make
cp f2c.h $INSTALL/include
cp libf2c.a $INSTALL/lib
cd ../src
cp makefile.u Makefile
make
cp f2c $INSTALL/bin
cd ..
mkdir -p $INSTALL/share/man/man1
cp f2c.1t $INSTALL/share/man/man1
cp fc $INSTALL/bin/f77
chmod +x $INSTALL/bin/f77
cd ..
rm -rf f2c
echo "==================SUMMARY=================="
echo $0 " has built and installed:"
find $INSTALL -name '*f2c*' -mmin -5
find $INSTALL -name '*f77*' -mmin -5

(上記サイトからの引用)

ですが,このスクリプトを実行すると


/bin/sh: ./xsum: Permission denied
make: *** [xsum.out] Error 126

と,パーミッションで怒られてしまいます.そこで

chmod +x f2c/src/xsum 

で実行権限を付与し,もう一度実行したところ,今度は,

/bin/sh: ./xsum: cannot execute binary file
make: *** [xsum.out] Error 126

と怒られ,八方塞がりになってしまいました.

いろいろいじってみてもうまくいかなかったので,一度xsumバイナリファイルを削除し,

cc -O xsum.c -o xsum 

でコンパイルしなおしてあげた結果,無事f2c, f77のインストールが終了しました.

なので最終的に,上記インストールスクリプトに


cd ../src
cp makefile.u Makefile
rm xsum                #追加
cc -O xsum.c -o xsum   #追加
chmod +x xsum          #追加
make
cp f2c $INSTALL/bin

この三行を追加してあげれば動くはずです.

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2