Fortran Compilers

There are two free/open-source compilers for Unix-like operating systems that support modern Fortran versions:

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 is still in development and therefore less mature than GNU Fortran. For instance, there is no Unicode support yet in Flang 5.

Certainly, there are even more Fortran compilers available, like Intel Fortran, PGI Community Edition, or the abandoned Open64. Most of them have Linux support, but won’t produce native binaries for FreeBSD or other Unix systems. 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 the Microsoft FORTRAN Compiler for DOS

On-line Compilers

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

You may want to try some of the examples in the next sections by using an on-line 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. Both can be installed from Ports or by using the FreeBSD package manager.

Install Flang with:

# pkg install devel/flang
# flang --version
clang version 5.0.0
Target: x86_64-portbld-freebsd11.1
Thread model: posix
InstalledDir: /usr/local/flang/bin

Install GNU Fortran with:

# pkg install lang/gcc7
# gfortran7 --version
GNU Fortran (FreeBSD Ports Collection) 7.2.1
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The Intel Fortran compiler for FreeBSD has been removed in 2010.