Reputation:
Is there is a way to put .mod files, generated by gfortran (GCC), into a separate output directory? I know how to place object files or other output with the -o flag as in:
gfortran -c test.f03 -o /path/to/output/dir/test.o
But the .mod files (which are generated by the above call) are not affected by the -o flag and placed in the current directory. Some commercial compilers have a flag like -qmoddir, but I cannot find something similar for gfortran.
If there's no such flag, is it possible to generate the .mod files in an extra step to get the -o flag to work?
Upvotes: 9
Views: 7938
Reputation: 15561
As per official documentation (-Mdir
gave gfortran: error: unrecognized command line option ‘-Mobj’
):
-Idir
These affect interpretation of the INCLUDE directive (as well as of the #include directive of the cpp preprocessor).
Also note that the general behavior of -I and INCLUDE is pretty much the same as of -I with #include in the cpp preprocessor, with regard to looking for header.gcc files and other such things.
This path is also used to search for .mod files when previously compiled modules are required by a USE statement.
See Options for Directory Search in Using the GNU Compiler Collection (GCC), for information on the -I option.
-Jdir
This option specifies where to put .mod files for compiled modules. It is also added to the list of directories to searched by an USE statement.
The default is the current directory.
-fintrinsic-modules-path dir
This option specifies the location of pre-compiled intrinsic modules, if they are not in the default location expected by the compiler.
Upvotes: 5
Reputation: 753990
The GNU gfortran documentation indicates that -M
dir or its synonym -J
dir specifies the output directory for .mod
files.
Upvotes: 16