基于这个问题A Makefile with Multiple Executables,我正在尝试编写一个fortran版本。
源代码分为多个* .f90文件。因此,我尝试使用之前引用的想法,这是我的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
当时的想法是调用时
make
在Linux终端中,结果应该是两个不同的可执行文件。不过,我收到以下消息:
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
我会根据提示和建议向您致敬。-