Your program can be contained in various source files, all stored in the same directory or organised in some convenient directory tree. The details of the organisation depend on personal taste, arrangements made by the group of developers you belong to, or simply the history of the program. Whatever the directory structure is, you will encounter a situation where the compiler needs assistence in order to compile a particular source file:
Compilers support options like -I
to indicate where these include
files and module intermediate files are to be found. Suppose we store
the two files of our tabulate
program in the following directory
structure:
tabulate/
main/
tabulate.f90
sub/
functions.f90
Compiling the file “functions.f90” with the commands
$ cd sub
$ gfortran -c functions.f90
leads to this structure:
tabulate/
main/
tabulate.f90
sub/
functions.f90
user_functions.mod
functions.o
To successfully compile and subsequently build the program we need to tell the compiler where it can find the file “user_functions.mod”:
$ cd main
$ gfortran -c tabulate.f90 -I ../sub
$ gfortran -o tabulate tabulate.o ../sub/functions.o
The result:
tabulate/
main/
tabulate.f90
tabulate.o
tabulate (or tabulate.exe on Windows)
sub/
functions.f90
functions.o
user_functions.mod
Notes:
-I
option should be
followed by a space and then the name of the directory, sometimes the
directory should come consecutively.-J
, for instance:
-J../include
(so that the .mod files could all appear in the
same directory)