Fatal Error: Cannot open module file

@YuanSun ,

Welcome to Fortran Discourse!

Re: “Could anyon help me?” - please never forget that “anyone” who can help you is you yourself! And when it comes to Fortran, a good place to start is the following:

Re: your specific question, please note the issue has to do with specific intricacies with static compilation steps around Fortran processors (compilers) and file locations, etc.

Say, you have a file named controlMod.f90 like so in a particular folder:

   use UrbanParamsType, only : UrbanReadNML
end
C:\temp\>dir
..
 Directory of C:\temp

10/20/2023  10:32 AM    <DIR>          .
10/20/2023  10:32 AM    <DIR>          ..
10/20/2023  10:32 AM                50 controlMod.f90
10/20/2023  10:31 AM    <DIR>          utils
               1 File(s)             50 bytes
..

Then if you try the process the Fortran source as follows using gfortran compiler:

C:\temp>gfortran -c controlMod.f90
controlMod.f90:1:8:

    1 |    use UrbanParamsType, only : UrbanReadNML
      |        1
Fatal Error: Cannot open module file 'urbanparamstype.mod' for reading at (1): No such file or directory
compilation terminated.

So you will notice gfortran is looking for a compiled module file ‘urbanparamstype.mod’ and unable to locate it and issuing the error.

Whereas you may have the file but it may be in a separate location (say as an example c:\temp\utils) but which gfortran was not informed of:

C:\temp>cd utils

C:\temp\utils>dir
..
 Directory of C:\temp\utils

10/20/2023  10:41 AM    <DIR>          .
10/20/2023  10:41 AM    <DIR>          ..
10/20/2023  10:31 AM                96 UrbanParamsType.f90
10/20/2023  10:40 AM               244 urbanparamstype.mod
10/20/2023  10:40 AM               743 UrbanParamsType.o
               6 File(s)          1,083 bytes
..

So knowing this, if you inform the path of the .mod file, then you will find the compiler complete the processing with no errors:

C:\temp>gfortran -c -Ic:\temp\utils controlMod.f90

C:\temp>

Look at the link below re: how the -Idir option helped resolve the error: