3

I have a Fortran program that uses modules, i.e. it creates .mod-files during compilation. I also wrote a Makefile that uses all the .f90-files from src/ puts all created .o-files in obj/ and the binary in the current folder, and everything works fine.

I now recompile my program in different folders for different calculations (say calc1/), i.e. I copy the Makefile into calc1/, type make all in calc1/ and all it does is the linking, because the object-files already exist. However, if the program includes any modules the compiler needs the corresponding .mod-files to be present in calc1/. Until now, I recompiled everything (make clean all), but with the program growing this takes too much time!

A possible solution I came up with is to have one specific folder for the binaries (bin/). But this is not a viable option because I have jobs in the queue, which obviously need a stable binary, while I also try new features in the meantime.

So, I'm looking for a solution that somehow treats the .mod-files similar to .o-files, e.g. places them in obj/.

4

1 回答 1

5

I would expect that (most?) compilers would specify an option to change the module file path. with gfortran, the option is -J or -M (from the man page):

-Jdir
-Mdir
       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.

       -M is deprecated to avoid conflicts with existing GCC options.

I think that most compilers look for .mod files in directories included with -I

EDIT

As of gfortran 4.6, -M is no longer supported. Use -J

based on one of my configure scripts, the flag is -module for ifort and pgf90 although I almost never use those compilers these days so somebody else should confirm that ...

于 2012-04-12T13:23:25.670 回答