1

I have a simple Makefile to compile and link a small FORTRAN code. I am quite new to using Makefile. The make file is given below. It works perfectly fine on a UNIX system (OS X) but when I try it in a Linux system it gives the following error message:

gfortran -std=f2003 -g -c m_getoptions.F03
gfortran: m_getoptions.F03: linker input file unused because linking not done
gfortran -std=f2003 -g -c m_readwf.F03
gfortran: m_readwf.F03: linker input file unused because linking not done
gfortran -std=f2003 -g -c ptdwf.F03
gfortran: ptdwf.F03: linker input file unused because linking not done
gfortran -std=f2003 -g -o TDWF ptdwf.o m_getoptions.o m_readwf.o
gfortran: ptdwf.o: No such file or directory
gfortran: m_getoptions.o: No such file or directory
gfortran: m_readwf.o: No such file or directory
make: *** [TDWF] Error 1

I have GNU make 3.81 on both systems. Any ideas.

# Makefile for PTDWF.
#
.SUFFIXES:
.SUFFIXES: .o .mod .F03
#
#
#
#
#Compiler options
#FC = $(FC)
#FC =  ifort
FC = gfortran -std=f2003
FFLAGS=-g
#
OBJS=ptdwf.o m_getoptions.o m_readwf.o
TDWF: $(OBJS)
#
#
        $(FC) $(FFLAGS) -o TDWF $(OBJS)
%.o:%.F03
        $(FC) $(FFLAGS) -c $<
#
clean:
        rm -f *.o *.mod TDWF
# DO NOT DELETE THIS LINE - used by make depend
ptdwf.o: m_getoptions.o m_readwf.o
R.U.
  • 355
  • 1
  • 5
  • 12

1 Answers1

3

The extension F03 is not a valid Fortran extension recognized by gfortran. Gfortran uses the extension .f for fixed-form code and .f90 for free-form code. The variants with capital F (.F, .F90) indicate the source should be pre-processed prior to compilation. The extension does not indicate the standard used to compile the source.

To fix your error, rename your files, or use a different compiler (e.g. ifort) that offers more leeway in source filenames. In general it is not a good practice to name your files by standard, and no other language does this (e.g. you dont see .c89, .c99, .cpp11, .cc14, etc).

Another solution (thanks to francescalus for this) is to add the option -x <language> to your gfortran command line, where valid options for <language> are f77, f77-cpp-input, f95, or f95-cpp-input. For modern Fortran source needing preprocessing, the option -x f95-cpp-input would be the correct choice.

casey
  • 6,855
  • 1
  • 24
  • 37
  • Or `-x f95-cpp-input` (etc). [Having a sensible file suffix the better, but for completeness gcc can be explicitly told how to process a file.] – francescalus Aug 18 '15 at 14:49
  • I seem to remember using `.f77` extension — quite a long time ago. The language has changed enough (Fortran IV, aka Fortran 66, was quite different in many, many ways from Fortran 77, and Fortran 90 and Fortran 2003 are different again — at least, 90 is different from 77) that it makes some sense to tag the code with the version. – Jonathan Leffler Aug 18 '15 at 14:51
  • @casey Many thanks. It has fixed my problem. Yes I was being naive in putting `.F03` extensions. I guess I saw somewhere and didn't realize it would create a problem. But I have learned by lesson. – R.U. Aug 18 '15 at 14:54
  • @francescalus thanks, I didn't know that one and have added it to the post. – casey Aug 18 '15 at 14:54
  • @JonathanLeffler there may be some merit to that, but with the caveat that (for gfortran at least), the extension does not influence the compilers choice of standard to use -- for gfortran, both .f and .f90 default to Fortran 95 w/ GNU extensions. – casey Aug 18 '15 at 15:09