Saturday, September 11, 2010

Install gfortran: Windows Binary Installation

I have just installed gfortran on Windows XP using a binary installation. Some binary installation options for Windows can be found at http://gcc.gnu.org/wiki/GFortranBinaries. Below is an outline of the binary options that are available.

  • MinGW (Minimalist GNU for Windows) - The "native Windows" build. Only release versions of gcc/gfortran are distributed. Latest version 4.5.1. http://www.mingw.org/
  • Unofficial build of gfortran 4.6 - Comes equipped with an installer that the gfortran wiki claims is simple to use. Claims binary installation works on Windows XP. Latest version 4.6.x. http://users.humboldt.edu/finneyb/gfortran-windows.exe
  • Equation.com - Binary builds that are, "are said to work well - but is not affiliated with any MinGW or GCC developer. Use at your own risk." They offer release builds in addition to the latest snapshot. Latest release version 5.4.1. Latest snapshot 4.6.2. http://www.equation.com/servlet/equation.cmd?call=fortran
  • Cygwin - A Unix like environment for Windows. Binary builds are provided, but Cygwin must be installed, which is something that takes time. For more information, see the Cygwin homepage http://www.cygwin.com/ and then check the gfortran wiki for links to the binaries and instructions if you decide to go that route. Latest version 4.6.x.

Of the above list, I have installed the binaries from MinGW, Equation.com, and Cygwin with success in the past. The Equation.com builds were the easiest to install, as I remember. In addition to the above installation options, I found another binary installation which I will be using for the purposes of this tutorial.

  • TDM-GCC - Provides an easy to use installer that has the added benefit of integrating nicely with an open source IDE. Only release versions of gcc/gfortran are available. Latest version 4.5.1.http://tdm-gcc.tdragon.net

I chose this option because of the advertised ability to easily integrate with the open source IDE (Integrated Development Environment) Code::Blocks. Here is a little more information about the TDM-GCC binary installation, from the TDM-GCC README file:

This edition of TDM-GCC is an unofficial replacement for the official GCC binaries distributed by the MinGW project; please note the following caveats: TDM-GCC is not formally affiliated with or endorsed by the MinGW project. No level of support for TDM-GCC is in any way guaranteed, although a best effort is made to fix bugs as they are found or forward them to GCC Bugzilla.

Using the TDM/MinGW installer is highly recommended; it can automatically install TDM-GCC (or the official MinGW GCC) as well as all supplementary base system packages. The installer uses a standard wizard interface with reasonable defaults.

TDM-GCC Installation

The installation process for this binary installation could not have been easier. From the download page http://tdm-gcc.tdragon.net/download, I selected the "Bundle Installer" option. Downloading the 20MB file "tdm-gcc-4.5.1.exe" goes quickly and then installation is ready to begin. Luckily, TDM-GCC provides a very nice installer that does pretty much everything. Run "tdm-gcc-4.5.1.exe" to launch the wizard installer. We are interested in installing gfortran, however, we will also be installing gcc with their installer. When the wizard launches, following these steps:

  • Select "Create" to, "create a new TDM-GCC installation."
  • On the next screen, select "MinGW/TDM 32-bit."
  • Enter an installation directory. I suggest keeping the default location "C:\MinGW32"
  • Select the mirror to download any updates from. Again, just keep the default (SourceForge).
  • A list of components is shown. Expand the first item under "Components" which is named "gcc (TDM-GCC Current: 4.5.1-tdm-1)." From the options that drop down, check the box next to "fortran" to ensure that gfortran is installed by the installer. See the screen shot below:

Once you've completed the previous step, click "Install" and wait for the installer to download any updates and complete the installation of gcc/gfortran.

The default wizard options add the necessary directories to the path. To test if the installation was successful, open a command window (Start Menu->Run), enter cmd (see below), and press OK to launch the command line window (equivalent of Terminal on Mac/Linux).

The Windows command line operates much in the same way the Terminal does on Mac/Linux. For example, to test if our gfortran installation was successful, enter the following on the command line:

> gfortran
gfortran: no input files

The gfortran commands for compiling and building are the same as discussed in "Hello!", the previous post below. The only difference is that when a built executable is to be run from the Windows command line, it is invoked with just the file name and nothing else. For example, to build and run our HelloProgram.f95 on Windows, use the following:

> gfortran HelloProgram.f95 -o hello
> hello
Hello!

IDE and Debugger

As mentioned previously, Code::Blocks is an IDE for Windows that was created for use with C/C++. However, there appears to be a Fortran plugin that supports Fortran syntax highlighting, building Fortran projects, and debugging features. It works well with the TDM-GCC binary distribution that was just installed. The Fortran plug-in can be found at http://darmar.vgtu.lt. From the download page, I chose the installation file CodeBlocks_Fortran_v0.4.1_Win32.zip.

Installation instructions are provided at the above website. I have copied the instructions that will allow Code::Blocks to be interfaced properly with the TDM-GCC installation we just installed.

Windows users may need to help Code::Blocks to find MinGW and Fortran compiler on their system. Short instruction:

In Code::Blocks open "Settings -> Compiler and Debugger..." dialog. Find "GNU Fortran Compiler". Open "Toolchain executables" tab. Fill "Compiler's installation directory" text-box (in our case it is C:\MinGW32).

For example, see the "Toolchain executables" tab filled out correctly below. Would also be valid if the "mingw32-" was removed from each of the fields where it currently resides (check the folder C:\MinGW\bin to see which executables are present).

There seems to be a minor bug (the debug toolbar does not appear) when running the codeblocks.exe file provided in the .zip file from http://darmar.vgtu.lt. This is remedied by launching Code::Blocks with the codeblocks_portable.bat file which is located in the same directory.

Besides that minor glitch, everything seems to work great. Debugging works quite well. There is an option which allows variables to be viewed during debugging, found in “Debug->Debugging Windows->Watches.” There are also other debugging options, such as the ability to view the memory stack.

The IDE discussion might warrant a separate post.

3 comments:

  1. Hi many thanks it was very useful I am actually a beginner and I stopped in the installation of Gun plot because I am not finding something compatible with the Windows 64 bits which should be in the http://darmar.vgtu. download files
    kindly can u assist me to continue

    ReplyDelete
  2. thank you so much for this!

    ReplyDelete
  3. Thanks, this was very helpful! I used TDM-GCC 4.8.1 (64bit) and Code Blocks 13.12

    ReplyDelete