Fortran Compilers
There are several free compilers available or up-coming for Unix-like operating systems that support modern Fortran language standards:
- Flang
- Front-end for LLVM, with limited support of the Fortran 2003 and 2008 language standards. Based on source code of PGI.
- Flang/F18
- LLVM front-end for Fortran 2018 in development, contributed by NVIDIA.
- GNU Fortran (gfortran)
- Modern Fortran compiler, part of the GNU Compiler Collection and successor of g77.
- Intel oneAPI Fortran
- Intel’s LLVM-based Fortran, C, and C++ compilers for Windows, Linux, and
macOS (freeware).
- IBM XL Fortran
- Proprietary no-charge full-function Community Edition of IBM’s Fortran compiler for Linux.
- LFortran
- A Fortran 2018 REPL-like front-end for LLVM, in pre-alpha stage.
GNU Fortran is a fork of G95, a discontinued Fortran 95 compiler that has been removed from the FreeBSD ports collection 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.
Fortran compilers are available for many platforms. Most of them target Microsoft Windows and/or Linux, but do not produce native binaries for FreeBSD and other Unix systems, like Intel Fortran, PGI Community Edition, or the abandoned Open64.
Some historic compilers for FORTRAN 77 are open-source as well:
- f2c, a FORTRAN 77 to C transcompiler (Linux, Unix, Windows, …),
- GNU Fortran 77 (g77), predecessor of gfortran (Linux, Unix, Windows, …),
- Open Watcom FORTRAN 77 (DOS, Linux, OS/2, Windows).
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.
- Fig. 1: Box of Microsoft FORTRAN Compiler for DOS
Online Compilers
There are services that provide online access to Fortran compilers, to build and run Fortran programs through the web browser, like:
- LFortran,
- Rextester (GNU Fortran 5.4.0),
- OnlineGDB (GNU Fortran 5.4.0),
- Tutorials Point (GNU Fortran 7.1.1, only Fortran 95 standard).
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 currently limits the list of available compilers to GNU Fortran and Flang, as Flang/F18 is still in early stage and LFortran is just a prototype. All four can be installed from ports or by using the FreeBSD package manager. The Intel Fortran compiler for FreeBSD was removed from the ports collection in 2010.
- Installing GNU Fortran:
# pkg install lang/gcc13 # gfortran13 -v Using built-in specs. COLLECT_GCC=gfortran13 COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc13/gcc/x86_64-portbld-freebsd13.2/13.1.0/lto-wrapper Target: x86_64-portbld-freebsd13.2 Thread model: posix Supported LTO compression algorithms: zlib gcc version 13.1.0 (FreeBSD Ports Collection)
- Installing Flang:
# pkg install devel/flang # flang --version clang version 7.0.1 Target: x86_64-portbld-freebsd12.0 Thread model: posix InstalledDir: /usr/local/bin
- Flang/F18 is included in port
devel/llvm-devel
(build optionFLANG
must be enabled):
At the current development stage, only FORTRAN 77 is covered.# pkg install devel/llvm-devel # flang-new-devel -v flang-new version 17.0.0 Target: x86_64-portbld-freebsd13.2 Thread model: posix InstalledDir: /usr/local/llvm-devel/bin
- Installing LFortran:
# pkg install lang/lfortran # lfortran Interactive Fortran. Experimental prototype, not ready for end users. LFortran version: 0.19.0 * Use Ctrl-D to exit * Use Enter to submit * Use Alt-Enter or Ctrl-N to make a new line - Editing (Keys: Left, Right, Home, End, Backspace, Delete) - History (Keys: Up, Down) >>>
References
- Fortran Wiki: Compilers
- Fortran-Lang.org: Compilers
- Wikipedia: List of Fortran compilers
< Introduction | [Index] | Editors and IDEs > |