gfortran on MacOS
If you just want to use the precompiled gfortran, use
APT/RPM as follows.
How to Install a Precompiled Binary
Package
A binary package is available as an RPM which can be installed using
APT/RPM as
$ sudo apt-get update
$ sudo apt-get install gcc
$ sudo apt-get clean
Notice that this will replace your default gcc compilers (gcc and g++), which is necessary to allow mixed use of C, C++, and FORTRAN for a single application.
The default gcc compilers can be switched by using the "altarnatives" command as follows
and answering the questions:
$ sudo alternatives --config gcc
REMARKS
- The gcc suit including gfortran is not yet officially supported for M1 Macs, so use it at your own risk.
Special care must be taken if you want to call fortran subroutines/functions with "character*" arguments from C/C++, since if the number of arguments exceeds a certain threshold, the string lengths are not properly passed to the fortran side, which was the major obstacle I encountered to make cernlib work on my M1 box.
- As a general rule, you should make sure
that optimization does not change your results.
- Avoid too many else if's in the same
level. You sometimes need to nest them, if the compiler abends.
- gfortran forbids jumping into a different
"IF" block.
- gfortran does not initialize a "BLOCK DATA"
even if you declare it "EXTERNAL". In order to force it, say "blkdat",
initialized, I needed a trick like
external blkdat
call dummysub(blkdat)
with
subroutine dummysub(a)
return
end
- gfortran now returns IOSTAT=5002 (instead of IOSTAT=3 as with gcc-4.2 or older), when the EOF is
reached for an random access file, which behavior is different from
that of g77.
- Here is a sample FCFLAGS I usually use to compile my legacy
fortran programs:
FCFLAGS = -fno-automatic
-fno-second-underscore -fno-range-check -fallow-argument-mismatch -fallow-invalid-boz -undefined warning
Back
to Keisuke Fujii's HEP on X Page
keisuke.fujii@kek.jp January 11, 2025