I am trying to compile a preprocessed Fortran source file that contains a syntax error: $ cat main.f90 implicit none a = 5 end program $ gfortran -cpp -E main.f90 -o main.f90.pp.f90 $ gfortran main.f90.pp.f90 main.f90.pp.f90:2:3: # 1 "<built-in>" 1 Error: Symbol ‘a’ at (1) has no IMPLICIT type The problem is that the error message refers to the preprocessed file and not the original source file. Also, it is showing an incorrect line above the number "1", which should be the offending line. This is unlike the C compiler: $ cat main.c int main() // { return 0; } $ gcc -E main.c -o main.c.pp.c $ gcc main.c.pp.c main.c: In function ‘main’: main.c:2:3: error: expected declaration specifiers before ‘return’ return 0; ^~~~~~ main.c:3:1: error: expected declaration specifiers before ‘}’ token } ^ main.c:3:1: error: expected ‘{’ at end of input where the error message refers to the correct source file (main.c:2:3). This issue was brought up at https://gitlab.kitware.com/cmake/cmake/issues/17160#note_301744 and it inhibits the correct behavior of CMake with the Ninja generator.
Try adding -fpreprocessed.
Thank you! This seems to work. Because I had no such issues with ifort, I assumed it was a gfortran bug.