1

based on this question A Makefile with Multiple Executables I am trying to write a fortran version.

The source code is divided in several *.f90 files. So I tried to use the idea quoted before, here's an excerpt of my makefile:

PROGRAM := Mpois Mkvz

# Definitions
COMPILER := gfortran -O3 -ffast-math
LIBS := -fbounds-check -lm

# Directories of object code
OBJDIR = objects

SOURCES_pois  := BORDERS.f90  CONVERGENCE.f90  FILESIO.f90  LBM.f90 Main_pois.f90
OBJECTS_pois  := BORDERS.o  CONVERGENCE.o  FILESIO.o  LBM.o Main_pois.o

SOURCES_kvz  := BORDERS.f90  CONVERGENCE.f90  FILESIO.f90  LBM.f90 Main_KVZ.f90
OBJECTS_kvz  := BORDERS.o  CONVERGENCE.o  FILESIO.o  LBM.o Main_KVZ.o

#   Linking
Mpois: $(OBJECTS_pois)
    $(COMPILER) $^ -o $@ $(LIBS)

#   Compiling
$(OBJECTS_pois): $(OBJDIR)/%.o: %.f90
    $(COMPILER) -c $< -o $@

#   Linking
Mkvz: $(OBJECTS_kvz)
    $(COMPILER) $^ -o $@ $(LIBS)

#   Compiling
$(OBJECTS_kvz): $(OBJDIR)/%.o: %.f90
    $(COMPILER) -c $< -o $@

clean:
    rm -f $(OBJDIR)/*.o

The idea was that when invoking

make

in a linux terminal the results should be two different executable files. Nevertheless I receive the following message:

makefile:21: target `BORDERS.o' doesn't match the target pattern
makefile:21: target `CONVERGENCE.o' doesn't match the target pattern
makefile:21: target `FILESIO.o' doesn't match the target pattern
makefile:21: target `LBM.o' doesn't match the target pattern
makefile:21: target `Main_pois.o' doesn't match the target pattern
makefile:29: target `BORDERS.o' doesn't match the target pattern
makefile:30: warning: overriding commands for target `BORDERS.o'
makefile:22: warning: ignoring old commands for target `BORDERS.o'
makefile:29: target `CONVERGENCE.o' doesn't match the target pattern
makefile:30: warning: overriding commands for target `CONVERGENCE.o'
makefile:22: warning: ignoring old commands for target `CONVERGENCE.o'
makefile:29: target `FILESIO.o' doesn't match the target pattern
makefile:30: warning: overriding commands for target `FILESIO.o'
makefile:22: warning: ignoring old commands for target `FILESIO.o'
makefile:29: target `LBM.o' doesn't match the target pattern
makefile:30: warning: overriding commands for target `LBM.o'
makefile:22: warning: ignoring old commands for target `LBM.o'
makefile:29: target `Main_KVZ.o' doesn't match the target pattern
gfortran -O3 -ffast-math -c  -o BORDERS.o
gfortran: fatal error: no input files; unwilling to write output files
compilation terminated.
make: *** [BORDERS.o] Error 4

Looking after hints and advice I salute you.-

Andres Valdez
  • 164
  • 17
  • What value do you expect `$(Main_pois)` to have? – francescalus Jun 26 '18 at 22:03
  • Use tag [tag:fortran] for all Fortran questions. Fortran 90 is just one old standard version and this question is not even version-specific. – Vladimir F Героям слава Jun 26 '18 at 22:08
  • @francescalus I was expecting to store in $(Main_pois) the definition of the program related to $(Main_pois). – Andres Valdez Jun 26 '18 at 22:12
  • @VladimirF oks oks I wanted to be specific with the tag... – Andres Valdez Jun 26 '18 at 22:13
  • You don't set the value in the file or command line shown. If you do set it in some way, do you still have problems? Same with `$(Main_KVZ)`. – francescalus Jun 26 '18 at 22:14
  • You can add a version tag to the main one to be specific, but there is nothing specific Fortran 90 here except the .f90 suffix, which is used by all modern Fortran versions, not just Fortran 90. – Vladimir F Героям слава Jun 26 '18 at 22:17
  • @francescalus I don't understand your question. I thought that the definition was done $(Main_pois): $(OBJECTS_pois) – Andres Valdez Jun 26 '18 at 22:18
  • You don't have anything like `Main_pois=...`. `$(Main_pois): ...` is a rule not a definition. If that's your confusion then I suppose that's the basis of your answer. So, are those things you don't understand? – francescalus Jun 26 '18 at 22:31
  • @francescalus mmmm, strange because I adapted this makefile from a working one trying to follow the idea of the reference included in the question... I understood now your point – Andres Valdez Jun 26 '18 at 22:42
  • @francescalus I have included those definitions you mentioned. Now I am facing overriding warnings, and 4 errors I can not understand. got any ideas? – Andres Valdez Jun 27 '18 at 15:04
  • You are making this more difficult for yourself by using `$(OBJDIR)/`. It's possible to get things working with this, but I first suggest you try to understand the building without that complication. That is, use `%.o` rather than `$(OBJDIR)/%.o` and see where you are. – francescalus Jun 27 '18 at 15:12
  • @francescalus So I followed your advice. The errors are gone, but I have only one executable file, I thought I was going to receive Mpois and Mkvz as executable files... The *.o files are now in the same directory as the source files... – Andres Valdez Jun 27 '18 at 15:33
  • From the accepted answer on the linked question, you'll need something like `all: ex1 ex3` (change those to your executables). [My suggested change with `$(OBJDIR)` was to build in the current directory - placing elsewhere is a complication beyond what you are currently struggling with.] – francescalus Jun 27 '18 at 15:35
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/173901/discussion-between-andres-valdez-and-francescalus). – Andres Valdez Jun 27 '18 at 15:52

0 Answers0