Fortran Compilers

There are three free/open-source compilers for Unix-like operating systems with support for modern Fortran standards:

GNU Fortran (gfortran)
Modern Fortran compiler, part of the GNU Compiler Collection.
Flang
Fortran front-end for LLVM, based on source code of PGI.
F18
A rewritten front-end for LLVM in development, contributed by NVIDIA.
LFortran
An interactive LLVM-based Fortran 2018 compiler, in pre-alpha stage.
FC
Another Fortran 2018 front-end for LLVM 10 by CompilerTree, in development.

GNU Fortran is a fork of G95, a discontinued Fortran 95 compiler that has been removed from the FreeBSD ports collection some time ago due to deprecated dependencies that are required for building. Flang in an older front-end for LLVM, missing most features of Fortran 2008 and 2018. F18 is planned to replace Flang in 2020.

Fortran compilers are available for many platforms. Most of them target Microsoft Windows and/or Linux, but won’t produce native binaries for FreeBSD and other Unix systems, like Intel Fortran, PGI Community Edition, or the abandoned Open64. Please see the Fortran Wiki and Wikipedia for an overview.

Some historic compilers for ancient Fortran are open-source as well:

Proprietary compilers targeting CP/M, DOS (fig. 1), and Microsoft Windows can be downloaded from various web sites dedicated to historic software, like old-dos.ru or winworldpc.com.

Microsoft FORTRAN Compiler for DOS
Fig. 1: Box of Microsoft FORTRAN Compiler for DOS

On-line Compilers

Fortran code can be compiled and executed in your web browser by using online services, like:

You may want to try some of the examples in the next sections by using an online compiler.

Modern Fortran on FreeBSD

Using FreeBSD as a programming environment for modern Fortran limits the list of available compilers to GNU Fortran and Flang, as F18 is still in early stage. Both can be installed from Ports or by using the FreeBSD package manager. The Intel Fortran compiler for FreeBSD was removed in 2010.