1

I have written a make file as following:

COMPFLAGS     = -O3 -autodouble  

CFLAGS        = $(COMPFLAGS)
PFLAGS        = $(COMPFLAGS)
FFLAGS        = $(COMPFLAGS)
CCFLAGS       = $(COMPFLAGS)
CXXFLAGS      = $(COMPFLAGS)

LD  =   ifort

LDFLAGS       = $(COMPFLAGS)

MAKEFILE      = Makefile

OBJS          = f1.o \
        f2.o \
        f3.o \

PROGRAM       = f1

all:        $(PROGRAM)

%.o:    %.f90
     @$(LD) $(COMPFLAGS) -c $<

$(PROGRAM):     $(OBJS)  $(MAKEFILE)

        @$(LD) $(LDFLAGS) $(OBJS)  -o $(PROGRAM)
        @echo "done"

clean:
        @rm -f $(OBJS) core

when I execute make I get the following error:

f77 -O3 -autodouble    -c -o f1.o f1.f
/usr/bin/f77: Illegal option: -autodouble
make: *** [f1.o] Error 255

I should note that there is no *.f file, all files are *.f90.

Could you please advise me where I have made mistake?

Thanks a lot.

jww
  • 97,681
  • 90
  • 411
  • 885
SF.AF
  • 59
  • 6
  • `make` disagrees with you for some reason. Try running `make -n -d` (to print diagnostics — a lot of them — and not actually execute commands). You will probably find the information in the output, after looking for a while. – Jonathan Leffler Jun 11 '17 at 22:38
  • Also see [How to use gfortran for .f90 file extension?](https://stackoverflow.com/q/40034609/608639), [How can gfortran tell if I am compiling f90 or f95 code?](https://stackoverflow.com/q/10884260/608639), [Makefile with different source types](https://stackoverflow.com/q/8940552/608639), [cmake, fortran 2008, and .f08 file extension](https://stackoverflow.com/q/25005017/608639), [Correct suffix for Fortran 2003 source file - Intel Fortran compiler](https://stackoverflow.com/q/20269076/608639), etc. – jww Jun 12 '17 at 06:22
  • You are invoking gcc's `f77` compiler, instead of ifort. `-autodouble` is valid for `ifort` – dlmeetei Jun 12 '17 at 11:50

1 Answers1

0

This looks unusual:

LD  =   ifort
...

%.o:    %.f90
     @$(LD) $(COMPFLAGS) -c $<

LD is the linker, not the compiler. Perhaps something like:

CC = ifort
...

%.o: %.f90
     @$(CC) -std=f90 $(COMPFLAGS) -c $<

You might also need the -x option to tell the machinery is Fortran 90 and not something to be preprocessed:

%.o: %.f90
     @$(CC) -x f90 -std=f90 $(COMPFLAGS) -c $<
jww
  • 97,681
  • 90
  • 411
  • 885
  • Although I don't disagree that `LD` is the wrong variable name, although `CC` is the C compiler so it's only slightly better (why not use something like `F90`?), there's no way that making these changes would have fixed the problem described in the question. Make doesn't care in any way what variable name you use. Just in case future people come looking at this question and answer... – MadScientist Jun 12 '17 at 14:14
  • @MadScientist - Maybe it was the addition of `-std=f90`; or `-x f90 -std=f90`. I'm not a Fortran guy, so I certainly don't know the subtleties. But I still write my own makefiles and use various version of C++, so I think the additional options may have made the difference. – jww Jun 12 '17 at 17:34
  • The example in your question showed make trying to create a `.o` file from a `.f` file, but you said there were no `.f` files in your directory and that your source files were all named `.f90`. There's no way that these variable settings, or any options created in any variable assignment, will have any impact on the algorithm make uses to locate which file to compile. – MadScientist Jun 12 '17 at 19:58
  • @MadScientist - Oh, you are right. I did not notice the file extension disconnect. Perhaps he added them directly to `COMPFLAGS`, which were then added to other flags, like `CFLAGS` and `CXXFLAGS`. – jww Jun 12 '17 at 20:04
  • Oops sorry jww I thought SFAF responding... Mondays! – MadScientist Jun 12 '17 at 20:06
  • @SF.AF - Are you certain this cleared the issue for you? If it did not, then you should *not* accept the answer. Its OK to wait for a better one more applicable to your problem. – jww Jun 12 '17 at 20:11