0

So I have been trying to use the answers and the idea of this published question: Makefile: Compiling from directory to another directory

In the following excerpt code, you can see the definition of the directories, for sources and compilation objects.

all : Mpois Mkvz MBJ Mlid

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

# Directories of object code
OBJDIR = objects
SRCDIR = src

SOURCES := $(SRCDIR)/lbm_const.f90 $(SRCDIR)/BORDERS.f90 $(SRCDIR)/CONVERGENCE.f90 $(SRCDIR)/FILESIO.f90 $(SRCDIR)/LBM.f90
OBJECTS := $(OBJDIR)/lbm_const.o $(OBJDIR)/BORDERS.o $(OBJDIR)/CONVERGENCE.o $(OBJDIR)/FILESIO.o $(OBJDIR)/LBM.o

SOURCES_pois := $(SRCDIR)/Main_pois.f90
OBJECTS_pois := $(OBJDIR)/Main_pois.o

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

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

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

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

When running the makefile script I get the following error:

make: *** No rule to make target 'lbm_const.f90', needed by 'objects/lbm_const.o'.  Stop.

Interesting is to note that when SRCDIR = src changes to SRCDIR = . the makefile compiles even having files in folder src.

Andres Valdez
  • 164
  • 17

0 Answers0