How to install gfortran on Windows 10

FORTRAN is a powerful programming language that is often over-shadowed by the more popular mainstream programming languages. Setting up and using FORTRAN on Windows 10 using the GCC Installation Manager makes the process quick and easy.

Visit mingw.org using your favourite browser and click on the downloads tab. Then click on the mingw-get-setup.exe link as pictured below.

Save the file to your downloads directory and run the program when the download completes. The MinGW Installation Manager will appear from which you can choose the packages to be installed. Note that the MinGW Installation Manager is a separate “app” that can be run at any time to manage or change the installed packages.

The various packages available through the Basic Setup are pictured below and include The GNU Ada Compiler, the GNU FORTRAN Compiler, The GNU C++ Compiler, and The GNU Objective-C Compiler.

Click on the All Packages option to reveal a host of other packages that are available.

We installed all of the available compilers, including the GNU FORTRAN compiler.

Testing the Installation (gfortran)

Create a simple test program as shown below using an editor (Visual Studio Code) and save it as addNumbers.f90 (Note that you must use a file extension such as .f90 or .f95 or the program may not compile).

program addNumbers

! This simple program adds two numbers
    implicit none

! Type declarations
    real :: a, b, result

! Executable statements
    a = 12.0
    b = 15.0
    result = a + b
    print *, 'The total is ', result

end program addNumbers

Open a terminal (cmd.exe) session and compile the program by entering the following command: gfortran -c addNumbers.f90

Enter the following command to generate an executable file: gfortran -o addNumbers.exe addNumbers.f90

The program will compile to create the addNumbers.exe executable file. Type .\addNumbers at the prompt to run the file from the current location as Windows Powershell will not load commands from the current location by default.

The program and terminal session from Visual Studio Code are as pictured below:

FTN95 from Silverfrost Limited is a complete Fortran development environment and includes the powerful Plato IDE. Version 8.70 was just released as discussed in our recently published article “New Release of FTN95 Version 8.70.”

Related Articles and Resources

  • Winteracter – The Fortran GUI Toolset (Interactive Software Services Ltd – UK)
  • Gino – Graphics and GUI solutions for Fortran and C under Windows and Linux. (Bradly Associates).

4 thoughts on “How to install gfortran on Windows 10

  1. please Change the command to compile from “gfortran -c addNumber.f90” to “gfortran -c addNumbers.f90”

Leave a Reply to Joe Bob Cancel reply