This tutorial will run through using gfortran on DSC machines.
Click on any image to view it in a lightbox.
For starters, let's get MinGW/gfortran to compile and run the eponymous hello world program. The first thing to do is navigate to your preferred source code storage location, and write the hello world program.
Then, start MinGW.
And then navigate the MinGW shell so that its working directory is your program location.
At this point, you can run the gfortran compiler on your program to generate an executable.
Then, run the executable. You may run it from inside MinGW. However, since it's a native Windows exectuable, you may also run it from the command prompt, from a batch script, or by double clicking on the executable in the explorer window. For this program, running it from the explorer window merely flashes a console window.
At some point you may build up a code library that you would like to reference. gfortran contains options to ease the reuse of old code. In order to explore these options, lets compute the factorial of five. First, go to your prefered source directory, and write the program. The program is split up into two files: one that contains a factorial algorithm inside a module, and one that makes use of that module. The two files are split into disparate directories.
Start up MinGW, and navigate it to the directory containing the module (Whee.f90). Then, compile the Whee module without linking (the -c option). This will produce two object files, Whee.mod and Whee.o, that are ready to be linked into some other program.
Then, navigate to the directory containing the main program (FacFive.f90). Then compile it without linking. In order to compile, gfortran will need to know where any external modules are. The -I option can be used for this.
Finally, link all the object files together, specifying the name of the executable with the -o option. While this example does not use any dll libraries, if your own code uses them, you'll need to use the -L option. Run the program, and you should find that 5! = 120.