1

While trying to rebuild some ancient Fortran code using gfortran 10.2.0, I get the following from an include that contains a preprocessor #define:

$ gfortran preproc.f
minimal.inc:1:2:

    1 | #define UD_POINTER integer*8
      |  1
Warning: Illegal preprocessor directive
minimal.inc:2:7:

    2 |       UD_POINTER utmake
      |       1
Error: Unclassifiable statement at (1)

The minimal source file preproc.f looks like this:

      program preproc
      include 'minimal.inc'
      end program

...and minimal.inc is:

#define UD_POINTER      integer*8
      UD_POINTER utmake

The "Unclassifiable statement" error is obviously a consequence of the "Illegal preprocessor directive" warning. If I simply copy the 'include' contents into the source file it works fine, but this is not a suitable solution because I want to maintain separation of code between the application and the library where the include is from.

Adding -cpp does not change anything. Changing gcc/gfortran versions to as far back as 4.8.5 does not fix it. I haven't found a compiler flag that touches it. What's going on here? What can I do to get it to comprehend that #define?

  • 1
    You need to replace `include 'minimal.inc'` with `#include "minimal.inc"`. See [Include statement in a Fortran file](https://stackoverflow.com/questions/31456342/include-statement-in-a-fortran-file). – veryreverie Apr 14 '21 at 08:29
  • 1
    It had not occurred to me that the Fortran include statement and the CPP #include directive were distinct. Files included via the Fortran statement do not undergo further preprocessing, hence the #define was not picked up, hence the error. Thank you very much! – Ross Dickson Apr 14 '21 at 12:24

0 Answers0