The GNU GFORTRAN Compiler

We will be using a FORTRAN compiler called gfortran, created by the GNU project. It is available for a number of different platforms; we will be using the version for Windows.

The compiler is a command-line program. To use it, you will need to open a "DOS window" in Windows. To do this, go to the "Start" menu and select "Run". Type in "cmd" (without the quotation marks) and press Enter. A text-mode window should pop up with a prompt such as

          C:\>

You can type commands at the prompt. The input and output is in text mode. To close the window, type "Exit".

Creating an executable program is a two step process. First the source code is compiled to object code. The object code may or may not be stored as a separate file, depending on the compiler used and the compiler options. Second, the object code is linked with other collections of object code (including system libraries) to form an executable file.

The GNU gfortran compiler can be used for both the compilation phase and the linking phase of creating executable files.


Options

There are a number of options available for gfortran. We will not need all of them. Some of the options are:


Examples

Here are some examples of using gfortran with a few of the options given above.

For the compilation phase:

          gfortran -c -Wall prog1.f90

This compiles prog1.for and creates an object code file called "prog1.o", showing all warnings.

Notice that FORTRAN files normally have an extension of "f90". The object file has the same name but with an extension of "o".

For the linking phase:

          gfortran -g -Wall -o prog1 prog1.o

This links the object code file "prog1.o" into the executable file "prog1.exe". All warnings are displayed.

If we don't use any options, as in:

          gfortran prog1.f90

the result is that gfortran will first compile and then link, so we will now have two new files named "prog1.o" and "a.exe".

Notice that the executable file has an extension of "exe".