I’m compiling code from the SCHISM coastal model that I’ve modified to introduce some new functionality. When trying to compile it on macOS with GNU gfortran-14 (or 13) from Homebrew, I’m finding that no module interface foo.mod
files are being generated. They’re not in the source file directory, they’re not in the object output directory, they’re not in the working directory, and when -Jmoddir
is specified, they’re not in moddir/
either.
Here’s an example command line:
/opt/homebrew/bin/gfortran-14 -DMPIVERSION=2 -DSCHISM -DUSE_BMI -DUSE_HYDRO -DUSE_SCHISM -I/opt/homebrew/Cellar/open-mpi/5.0.3_1/include -I/opt/homebrew/Cellar/open-mpi/5.0.3_1/lib -I/Users/phil/Code/noaa/BUILD/schism_2025-01-21/include -O2 -ffree-line-length-none -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -mmacosx-version-min=14.6 --preprocess -fallow-argument-mismatch -ffree-line-length-none -c /Users/phil/Code/noaa/schism_NWM_BMI/src/Core/schism_glbl.F90 -o CMakeFiles/core.dir/schism_glbl.F90.o
That source file contains module schism_glbl
, and the command runs successfully, generating the specified object file. But, no corresponding schism_glbl.mod
anywhere I look. This ultimately fails my builds, because CMake is expecting to see those resulting module files to use in compiling later objects.
I’m not able to find anything online about when gfortran might not emit a module file. I’ve checked the GNU Fortran manual, its wiki, this Discourse, the CMake Discourse, and Googled more broadly. Does anyone know why this is happening, and/or what one can do about it?
I’ve done a bit more investigation, and it seems that it’s not even attempting to create the .mod
file!
Output from fs_usage
shows that it stat()
s the include directory before opening the source .f90
file, but does nothing else in there:
16:16:48.414019 getattrlist /Users/phil/Code 0.000011 gfortran-14.23014024
16:16:48.414022 readlink /Users/phil/Code 0.000003 gfortran-14.23014024
16:16:48.414068 getattrlist /Volumes/Cased/Code 0.000009 gfortran-14.23014024
16:16:48.414075 getattrlist /Volumes/Cased/Code/noaa 0.000007 gfortran-14.23014024
16:16:48.414080 getattrlist /Volumes/Cased/Code/noaa/schism_NWM_BMI 0.000005 gfortran-14.23014024
16:16:48.414084 getattrlist /Volumes/Cased/Code/noaa/schism_NWM_BMI/src 0.000005 gfortran-14.23014024
16:16:48.414097 getattrlist /Volumes/Cased/Code/noaa/schism_NWM_BMI/src/Core 0.000013 gfortran-14.23014024
16:16:48.414105 getattrlist /Volumes/Cased/Code/noaa/schism_NWM_BMI/src/Core/schism_glbl.F90 0.000008 gfortran-14.23014024
16:16:48.414136 stat64 /Volumes/Cased/Code/noaa/BUILD/schism_2025-01-21/Core 0.000005 gfortran-14.23014024
16:16:48.414138 stat64 /Volumes/Cased/Code/noaa/BUILD/schism_2025-01-21/Core 0.000002 gfortran-14.23014024
16:16:48.414143 getattrlist /Volumes/Cased/Code/noaa/BUILD/schism_2025-01-21/Core/CMakeFiles 0.000005 gfortran-14.23014024
16:16:48.414147 getattrlist /Volumes/Cased/Code/noaa/BUILD/schism_2025-01-21/Core/CMakeFiles/core.dir 0.000005 gfortran-14.23014024
16:16:48.414151 getattrlist [ 2] /Volumes/Cased/Code/noaa/BUILD/schism_2025-01-21/Core/CMakeFiles/core.dir/schism_glbl.F90.o 0.000003 gfortran-14.23014024
16:16:48.432787 stat64 /Volumes/Cased/Code/noaa/BUILD/schism_2025-01-21/include 0.000016 f951.23014025
16:16:48.432799 stat64 /Volumes/Cased/Code/noaa/schism_NWM_BMI/src/Core 0.000009 f951.23014025
16:16:48.432916 stat64 /Volumes/Cased/Code/noaa/BUILD/schism_2025-01-21/include 0.000004 f951.23014025
16:16:48.433095 open F=4 (R___________) /Volumes/Cased/Code/noaa/schism_NWM_BMI/src/Core/schism_glbl.F90 0.000020 f951.23014025
16:16:48.927048 lstat64 /System/Volumes/Data/Volumes/Cased/Code/noaa/BUILD/schism_2025-01-21/Core/CMakeFiles/core.dir 0.000090 fseventsd.21140652
16:16:49.027388 lstat64 /System/Volumes/Data/Volumes/Cased/Code/noaa/BUILD/schism_2025-01-21/Core/CMakeFiles/core.dir/schism_glbl.F90.o 0.000067 fseventsd.21140661
I did not see your original post, so it was good that you followed up. I use gfortran from homebrew on MacOS too, and the only time I’ve seen this kind of problem is when the source code had errors or when I did not have write permission in the working directory. One other possibility, which is rare, thankfully, is when the source code causes some kind of internal compiler error; the last time this happened was with a code that used some object oriented features, and I submitted a bug report as instructed by the compiler.
As far as I can tell, there is no error or failure. The compiler emits no messages, produces the object file as expected, and exits with code 0, indicating success.
I definitely have permissions on the entire directory tree in question - I can have CMake regenerate it from scratch, and the issue still reproduces.