忍者ブログ
MASTER →  ADMIN / NEW ENTRY / COMMENT
現代魔法(nearly equal 情報技術)を勉強中な人のメモ(チラシの裏)
/ 2024/04/26 (Fri) / 編集
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

/ 2009/06/02 (Tue) / 編集
FortranをMacOSX 10.5にインストール


mpfr : 4.2.2
mpfr : 2.3.1
GCC : 4.4
Fortranで頑張ってググったり、バイナリ落とそうと頑張ったりしたがなかなかうまくゆかず、、、どうすんだ?とおもったらどうやらfortranはgccに入っているらしい。
XcodeについてくるAppleのGCCには入ってないよ
In particular, Apple does not currently support the compilation of Fortran, Ada, or Java, although there are third parties who have made these work.
by man

gmp


GNU MP is a library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating point numbers. It has a rich set of functions, and the functions have a regular interface. GNU MP is designed to be as fast as possible, both for small operands and for huge operands. The speed is achieved by using fullwords as the basic arithmetic type, by using fast algorithms, by carefully optimized assembly code for the most common inner loops for a lots of CPUs, and by a general emphasis on speed (instead of simplicity or elegance).
というもの、めんどくさかったのでMacPortsでインストールしちゃったよ
%sudo port install gmp

mpfr


MPFR is a portable C library for arbitrary-precision binary floating-point computation with correct rounding, based on the GMP multiple-precision library. The computation is both efficient and has a well-defined semantics. It copies the good ideas from the ANSI/IEEE-754 standard for fixed-precision floating-point arithmetic.
というもの、めんどくさかったのでこれもMacPortsでインストールしちゃったよ
%sudo port install mpfr

gcc

上の二つをインストールしたらいよいよgcc、
gccもportに入ってたりするんだけど
%port variants gcc44
gcc44 has the variants:
universal
powerpc
odcctools: Use the odcctools instead of the system provided ones - does not work for x64 currently!
gfortran: Enables fortran; this language will be enabled in the final version - this variant is completely untested!
な感じなのでやめといたほうがよさげ

まずはソースコードをダウンロードしてコンパイルの準備
%wget 'ftp://ftp.gnu.org/pub/gnu/gcc/gcc-4.4.0/gcc-4.4.0.tar.gz'
%tar zxvf gcc-4.4.0.tar.gz
%mkdir gcc44
%cd gcc44

とりあえずconfigure
../gcc-4.4.0/configure -enable-languages=c,c++,fortran --enable-checking=release --disable-bootstrap --prefix=/usr/local/gcc44 --with-gmp --with-gmp-include=/opt/local/include --with-gmp-lib=/opt/local/lib --with-mpfr --with-mpfr-include=/opt/local/include --with-mpfr-lib=/opt/local/lib
  1. -enable-languages=c,c++,fortran
  2. CとC++とFortranを作るよ
  3. --enable-checking=release
  4. チェックをします
  5. --disable-bootstrap
  6. 面倒なテストを省略!コンパイルが早くなるらしい
  7. --prefix=/usr/local/gcc44
  8. 場所はともかく必ず指定、これやらないとデフォルトのgccに上書きされて泣きたくなることに、、、
  9. --with-gmp --with-gmp-include=/opt/local/include --with-gmp-lib=/opt/local/lib
  10. gmpのヘッダファイルとライブラリの場所を指定、gmpがないとconfigureでエラーが出る。。。
  11. --with-mpfr --with-mpfr-include=/opt/local/include --with-mpfr-lib=/opt/local/lib
  12. mpfrのヘッダファイルとライブラリの場所を指定、mpfrも必須

なんにもエラーがでなければmakeしてinstall
%make CC='cc -no-cpp-precomp' CFLAGS="-O2 -fomit-frame-pointer" all
%make install
make uninstallは存在しないらしいのでconfig.logなんかでオプションミスってないか確認してください。


というわけでインストールしたのがこれ
%/usr/local/gcc44/bin/gfortran -v
Using built-in specs.
Target: i386-apple-darwin9.7.0
コンフィグオプション: ../gcc-4.4.0/configure -enable-languages=c,c++,fortran --enable-checking=release --disable-bootstrap --prefix=/usr/local/gcc44 --with-gmp --with-gmp-include=/opt/local/include --with-gmp-lib=/opt/local/lib --with-mpfr --with-mpfr-include=/opt/local/include --with-mpfr-lib=/opt/local/lib
スレッドモデル: posix
gcc version 4.4.0 (GCC)


Hello World

fortranは拡張子にも決まりがあるらしい、とりあえず以下の内容の「hello.f90」を作成

program hello
print *, 'Hello Fortran World!'
end program hello
すると
%/usr/local/gcc44/bin/gfortran hello.f90 -o hello
%./hello
Hello Fortran World!

一方、ファイル名を「hello.f」にすると
%mv hello.f90 hello.f
%/usr/local/gcc44/bin/gfortran hello.f -o hello
hello.f:1.1:

program hello                                                           
 1
Error: Non-numeric character in statement label at (1)
hello.f:1.1:

program hello                                                           
 1
Error: Unclassifiable statement at (1)
hello.f:2.3:

  print *, 'Hello Fortran World!'                                       
   1
Error: Non-numeric character in statement label at (1)
hello.f:2.3:

  print *, 'Hello Fortran World!'                                       
   1
Error: Unclassifiable statement at (1)
hello.f:3.1:

end program hello                                                       
 1
Error: Non-numeric character in statement label at (1)
hello.f:3.1:

end program hello                                                       
 1
Error: Unclassifiable statement at (1)



Fortranはさっぱりわからない上に情報が錯綜しているので詳しくはまた今度、とりあえず「拡張子にも気をつけてね」という話

拍手[0回]

PR
忍者ブログ [PR]