A test case: >>>>>>>>> $ ls incdir/ moddir/ srcdir/ $ ls incdir/ $ ls moddir/ $ ls srcdir/ modtest.F90 $ cat srcdir/modtest.F90 module modtest integer a end module program main use modtest end $ gfortran --version GNU Fortran (GCC) 14.1.1 20240522 (Red Hat 14.1.1-4) Copyright (C) 2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ strace --follow-forks -o trace.log gfortran -Jmoddir -Iincdir srcdir/modtest.F90 $ <<<< >From trace.log: >>>> 231249 openat(AT_FDCWD, "moddir/modtest.mod", O_RDONLY) = -1 ENOENT (No such file or directory) 231249 unlink("moddir/modtest.mod") = -1 ENOENT (No such file or directory) 231249 rename("moddir/modtest.mod0", "moddir/modtest.mod") = 0 231249 openat(AT_FDCWD, "modtest.mod", O_RDONLY) = -1 ENOENT (No such file or directory) 231249 openat(AT_FDCWD, "srcdir/modtest.mod", O_RDONLY) = -1 ENOENT (No such file or directory) 231249 openat(AT_FDCWD, "incdir/modtest.mod", O_RDONLY) = -1 ENOENT (No such file or directory) 231249 openat(AT_FDCWD, "moddir/modtest.mod", O_RDONLY) = 5 <<<< i.e after moddir/modtest.mod is created - its searched for in the following order: - pwd - src-file-dir - -Ipath - -Jpath With this search order - a buggy/old/incorrect modtest.mod in pwd or src-file-dir gets picked up - resulting in broken builds. Checking ifx from OneAPI - i see: >>>> $ ifx --version ifx (IFORT) 2023.0.0 20221201 Copyright (C) 1985-2022 Intel Corporation. All rights reserved. $ ifx --help |& grep -A2 \\-module -module path specify path where mod files should be placed and first location to look for mod files <<<< Here with ifx - I don't get into the issue with picking up buggy/old/incorrect modtest.mod. With a slightly tweaked test: >>>>>>>> $ cat srcdir/modtest.F90 module modtest integer a end module program main use modtestwrong end $ strace --follow-forks -o trace.log ifx -module moddir -Iincdir srcdir/modtest.F90 srcdir/modtest.F90(5): error #7002: Error in opening the compiled module file. Check INCLUDE paths. [MODTESTWRONG] use modtestwrong ----^ compilation aborted for srcdir/modtest.F90 (code 1) $ <<< trace.log has: >>> 1573952 openat(AT_FDCWD, "moddir/modtestwrong.mod", O_RDONLY) = -1 ENOENT (No such file or directory) 1573952 openat(AT_FDCWD, "modtestwrong.mod", O_RDONLY) = -1 ENOENT (No such file or directory) 1573952 openat(AT_FDCWD, "srcdir/modtestwrong.mod", O_RDONLY) = -1 ENOENT (No such file or directory) 1573952 openat(AT_FDCWD, "./modtestwrong.mod", O_RDONLY) = -1 ENOENT (No such file or directory) 1573952 openat(AT_FDCWD, "incdir/modtestwrong.mod", O_RDONLY) = -1 ENOENT (No such file or directory) ... <<<< [i.e; -Jpath is searched first, then pwd, src-file-dir, ./, -Ipath, ...] So is this a bug in gfortran? thanks, Satish