Tuesday, September 27, 2016

Installing the gfortran compiler in Windows

The gfortran compiler is part of the GNU Compiler Collection (GCC). The first steps of creating a free and open source compiler were back in 2000. Starting from 2005 the compiler was stable enough to use it for production. Gfortran compiler supports the following variation of Fortran language:

  • Fortran 77 (Partial)
  • Fortran 95 
  • Fortran 2003
  • Fortran 2008 (Partial)

It is true that most people nowadays are running Windows, making it hard to use Unix-like tools in this environment. Fortunately, there is the Cygwin, a software package that provides the Unix-like environment and tools, including the FORTRAN and C compilers, in windows for free. I created these instructions for installing gfortran in windows.

The first step is to download the Cygwin installation from the site: cygwin.com/install.html. Depending on your operating system you can choose between 32 or 64bit. If you are not sure, try firstly the  64bit version and if it fails to start, use the 32bit.


Cygwin download page of the site.
Cygwin download page of the site.

After downloading the file you should execute it. Windows will complain that the binary is not verified, but you can safely ignore the message:

Warning windows message for unknown publisher
Warning windows message for unknown publisher. You can ignore it.

During the installation, the installer will ask you which server should use. Select one random. If you think it is slow, try to select something different. In the next important step, the installer will ask you about the packages to be downloaded. To select the FORTRAN compiler, go to "Devel" subtree and select the following packages: gcc-core, gcc-fortran, gdb.

Package selection of the Cygwin framework.
Package selection of the Cygwin framework.

Package selection of the Cygwin framework.
Selected GCC and Gfortran compilers.

In the next step, the installer will calculate the dependencies and it will suggest installing missing libraries and utilities:

Cygwin setup automatically calculated and installs the dependencies.
Cygwin setup automatically calculated and installs the dependencies.

The installation can take from few minutes up to an hour depending on the internet connection and the traffic on the selected server.

Installation process of the Cygwin
Installation process of the Cygwin

After installing the tools, you should check the options to create the desktop icon in both Desktop and start-menu. In your desktop you should have an icon with the title "Cygwin64 Terminal" or something similar, depending if you are using the 64 or 32bit version of tools.


After starting the terminal, you can go to your directory and compile your FORTRAN program. In my case, I had the source code in d:\fortran, so I went there and compile it, as you can see in the picture. I personally use the Notepad++ one of the best free editors you can find.

Compiling and executing a FORTRAN application in Cygwin using Notepad++ as an editor.
Compiling and executing a FORTRAN application in Cygwin using Notepad++ as an editor.

Installing gfortran on MAC. 


For installing the gfortran compiler in the MAC, the compiler team provides compilers on their site. You can visit gcc.gnu.org/wiki/GFortranBinaries and check the MacOS section. You should know what version of OS is installed on your machine.

MacOS installation packges for gfortran.
MacOS installation packges for gfortran.