GFortranis the name of the GNU Fortran project. The main wiki page offers many helpful links about GFortran, as well as Fortran in general. In this guide, the installation process for GFortran on Windows, Linux, macOS and OpenBSD is presented in a beginner-friendly format based on the information from GFortranBinaries.
Windows Subsystem for Linux (WSL): An official compatibility layer for running Linux binary executables on Windows. With Windows Subsystem for Linux GUI one can run text editors and other graphical programs.
Finally, you can switch between different versions or set the default one with the update-alternatives (see manpage). There are many online tutorials on how to use this feature. A well structured one using as an example C and C++ can be found here, you can apply the same logic by replacing either gcc or g++ with gfortran.
OpenCoarrays is an open-source software project that produces an application binary interface (ABI) used by the GNU Compiler Collection (GCC) Fortran front-end to build executable programs that leverage the parallel programming features of Fortran 2018. Since OpenCoarrays is not a separate compiler, we include it here, under gfortran.
While with gfortran you can compile perfectly valid code using coarrays, the generated binaries will only run in a single image (image is a Fortran term for a parallel process), that is, in serial mode. OpenCoarrays allows running code in parallel on shared- and distributed-memory machines, similar to MPI:
There is also a separate distribution of mingw-w64 that can be installed without MSYS2, but I don't recommend it, as the last files there have gcc-8.1.0, from 2018 (apart from a recent build by Ray Linn that includes the Ada, but not the Fortran compiler).
Another compiler that is now free is Intel Fortran : you have to install Microsoft Visual Studio Community, Intel oneAPI Base Toolkit and Intel oneAPI HPC Toolkit. More information here. Available on Linux, macOS and Windows (of course, Visual Studio is needed only on Windows). Intel oneAPI is at least partly open source, not sure about the Fortran compiler.
MSYS2 is a much smaller package (in terms of disk pace needed), and is used by several other free projects: R (Rtools), Octave and Strawberry Perl all include parts of it, including the gcc compilers.
To compile Fortran code for Windows you need a Fortran compiler for Windows. Microsoft neither provides a built-in one nor offers one for sale. Third-party compilers are available, including gfortran, but you'll need to install one yourself. If you want to use gfortran in particular, or if you like it simply because you don't have to spend money to get it, then I would recommend obtaining it as part of mingw-w64. Alternatives are available from multiple vendors, some free of charge, but most for sale.
Windows XP / Windows 7 Instructions
Below are instructions to install a free minimal FORTRAN compilationenvironment for Microsoft Windows users. There are two free products to install, the compiler itself (mingw) and a graphical front-end (Code::Blocks). 1. Download mingw from here: -get-inst/ 2. Double click on the installation file. It is recommended that you not change the default install location, which is c:\mingw.
During the installation be sure to select the Fortran Compiler in the component selection window as shown in the image below. 3. Download Code::Blocks for Fortran for Windows 32bit from this link:
4. Note that this version of Code::Blocks for Fortran does not require an actual installation. Simply unzip the downloaded package, then run the codeblocks.exe file directly from the resulting folder. You will be presented with the following options. Please check the option as shown in the image below. 5. To create a new fortran program click on file>New>File>Select Fortran Source>Hit Go and follow the instructions in the dialog box. 6. To open an existing fortran source file select File>Open> and navigate to the fortran source file.
Mac OSX Instructions
Below is the link to the instructions to download and install GCC 4.7,4.8 compiler suite. This compiler can be invoked using the OSX Terminal program. Note that the GCC 4.7,4.8 suite contains the required gfortran compiler. It can be downloaded by clicking on the link located just underneath the Computaion Tools :: C/Fortran section of the page.
Below is the link to the instructions to download and install Photran, an Eclipse-based integrated IDE for fortran.
Link: Florida State University
Tallahassee, FL 32306
The most convenient way to do the exercises is on your own computer after installing acompiler. The main choices are listedbelow. gfortran is the mostuniversal/popular, is completely free and can be usedon Windows, MacOSX or Linux. TheIntel compiler is probably the bestcompiler, is available free to individuals, and also works on Windows, MacOSX and Linux.
gfortran: Developed by the GNU,the free software foundation. See Linux: One of the optional packages to install. MacOSX: Install (i) Xcode (from App Store), (ii) XCode command line tools, (iii) gfortran from A good guide to this process is here. Windows: There are 3 main possibilities: (i) Install MinGW, which allows you to use gfortraninside a Command Prompt window. Follow these instructions, being sure to edit your path. (ii) Install Cygwin, which provides a unix-likeenvironment in which you can use gfortran(
www.cygwin.com - make sure to select fortran duringthe installation process; your files can be found inC:\cygwin64\home\yourname). (iii) Install Microsoft's Windows Subsystem forLinux (WSL), which allows you to run a full Linuxinstallation at the same time as Windows, as discussedhere and here.
A good editor that highlights Fortran syntax is also veryuseful. Emacs is a good one: for Mac the Aquamacsversion is nice, for Windows download the emacs-w64version. Another suitable one for Windows is Kate.
Since 2015 and GCC 5.1, a major version is published every year: the first stable 2022 version was therefore GFortran 12.1. Four subsequent minor versions are then published during the four next years (for example 11.2, 10.3, 9.4 and 8.5). It can be interesting to install several versions, the latest for bleeding edge features and older ones for their robustness. For example, it is not rare to see up to 10% variations in the CPU speed of your program depending on the GCC version, and the latest version is not always the fastest.
Parallel computation is achieved by exploiting different aspects of modern architectures: from vectorization instructions, multi-threading, message passing and offloading to GPU devices. The followings enable handling one or more of these aspects:
The first level of parallelism with vectorization can be achieved by the combination of -O3 and -march=native which enables the compiler to exploit the local machine vector instructions (SSE, AVX, AVX2, AVX512, etc):
OpenACC support was introduced in GCC 5. Depending on the target GPU architecture (Intel, Nvidia, AMD) different offloading backends are available, read here. For Nvidia PTX offloading, you need to install the following backend:
You can report bugs in the GCC Bugzilla system: first, update your major GFortran version to its latest release, then search if the bug was already reported, then file the bug. You can also use the GFortran mailing list
for...@gcc.gnu.org if you are uncertain on how to handle Bugzilla.
Anyone interested in joining the GFortran developers team should send an email to
gfor...@gcc.gnu.org or
jvde...@gcc.gnu.org to receive an invitation to join the GFortran Mattermost workspace (now hosted by the Oregon State University Open Source Lab), which was created in December 2022 to facilitate chat, patch discussions, mentoring new folks, etc. See also that January 2023 message by Paul Richard Thomas to comp.lang.fortran. And that 2008 message by Tobias Burnus to comp.lang.fortran contains advice that are still pertinent.
Unofficial GFortran 32-bit and 64-bit binary packages based on the current development source code can be found on For example, to install the latest 64-bit nightly binary in a Linux system, download and install the latest GCC trunk build:
From a user perspective, the most UNIX compatible Windowsdevelopment environment is through emulation, either via the Windows Subsystemon Linux, or facilitated by Docker. In a similar vein, traditionalvirtualization methods like VirtualBox are also reasonable methods to developUNIX tools on Windows.
Native Windows support is typically stunted beyond the usage of commercial compilers.However, as of 2022, most commercial compilers have free plans which are sufficient forgeneral use. Additionally, the Fortran language features supported by f2py(partial coverage of Fortran 2003), means that newer toolchains are often notrequired. Briefly, then, for an end user, in order of use:
Can also be used for gfortran. However, the POSIX API compatibility layer provided byCygwin is meant to compile UNIX software on Windows, instead of buildingnative Windows programs. This means cross compilation is required.
The compilation suites described so far are compatible with the nowdeprecated np.distutils build backend which is exposed by the F2PY CLI.Additional build system usage (meson, cmake) as described inF2PY and Build Systems allows for a more flexible set of compilerbackends including:
It is possible to use the resulting environment from a standard commandprompt. However, it is more pleasant to use a developer powershell,with a profile in Windows Terminal. This can be achieved by adding thefollowing block to the profiles->list section of the JSON file used toconfigure Windows Terminal (see Settings->Open JSON file):
3a8082e126