首页 > 解决方案 > 如何使用多个可执行文件为 fortran 编写 makefile

问题描述

基于这个问题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

照顾提示和建议,我向你致敬。-

标签: makefilefortrangfortran

解决方案


推荐阅读