gfortran: how to control output directory for .mod files

孤者浪人 提交于 2019-12-10 15:16:10

问题


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?


回答1:


The GNU gfortran documentation indicates that -Mdir or its synonym -Jdir specifies the output directory for .mod files.




回答2:


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.


来源:https://stackoverflow.com/questions/488333/gfortran-how-to-control-output-directory-for-mod-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!