Search code examples
gfortran

For what is it used -E flag with -cpp? (gfortran preprocessing options)


I'm using the following options:

touch foo.f90; gfortran -cpp -E -dM foo.f90

, but when I remove the -E flag I get this error:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status

As I used 'touch' the file is empty.


Solution

  • The -E flag is described in the manual.

    If you use the -E option, nothing is done except preprocessing. Some of these options make sense only together with -E because they cause the preprocessor output to be unsuitable for actual compilation.

    It makes the compiler to print the preprocessed source code instead of compiling it. That means preprocessed by cpp, the C preprocessor.

    If your source code is not a valid Fortran program, then trying to actually compile it (without the -E flag) naturally leads to some kind of error message.