HP Fortran Programmer's Guide (March 2010)
Compiling and linking
Special-purpose compilations
Chapter 2 91
$ do_stats
Enter an integer (hint: 77 is current average): 77
Average or better.
If instead of the preceding command line, the program had been compiled as follows:
$ f90 -o do_stats main.f90 data.f90 code.f90
the compilation would fail and f90 would print the error message:
Error FCE37 : Module STATS_CODE not found
The compilation would fail because the compiler cannot process main.f90 without
STATS_CODE.mod. But the order in which the program files appear on the command line
prevents the compiler from processing code.f90 (and thereby creating STATS_CODE.mod)
until after it has processed main.f90.
Compiling with make
If you use the make utility to compile Fortran programs, the description file should take into
account the dependencies created by modules. For example, to compile the do_stats program
using the make utility, the description file should express the dependencies as follows:
Example 2-5 makefile
# description for building do_stats
do_stats : main.o code.o data.o
f90 -o do_stats main.o code.o data.o
# main.o is dependent on main.f90 and code.f90
main.o : main.f90 code.o
f90 -c main.f90
# code.o is dependent on code.f90 and data.f90
code.o : code.f90 data.o
f90 -c code.f90
# data.o is dependent only its source, data.f90
data.o : data.f90
f90 -c data.f90
Note that the dependencies correspond to the order in which the source files are specified in
the following f90 command line:
$ f90 -o do_stats data.f90 code.f90 main.f90
Assuming that you name the description file makefile, the command line to compile the
program with make is:
$ make