Fortran: 生成文件错误
Fortran: makefile error
我有一个名为 solidsolver.f90 的 Fortran 主程序和一个名为 read_mesh.f90
的模块。该模块包含两个子程序,用于主程序。我可以手动编译它们,但不能使用 makefile。我的 makefile 名为 makefile.makefile
,它给我一个错误:
make: *** No targets specified and no makefile found. Stop.
我确实需要一个以简洁的方式编写的 makefile,因为将来我的代码将成倍增长。这是生成文件:
OBJECTS = read_file.o solidsolver.o
MODULES = read_file.mod
.PHONY: clean
main.exe: $(MODULES) $(OBJECTS)
gfortran $(OBJECTS) -o main.exe
%.o: %.f90
gfortran -c $<
%.mod: %.f90
gfortran -c $<
clean:
rm -f $(OBJECTS) $(MODULES) main.exe
GNU make
正在按以下顺序查找 makefile(来自手册页):
[...] GNUmakefile, makefile, and Makefile, in that order.
要使用名为 makefile.makefile
的文件,您需要明确告诉 make 使用该(非标准)文件:
make -f makefile.makefile
亚历克斯是对的。但实际上makefile的内容是错误的。我将其更改如下并且有效:
OBJECTS = read_file.o solidsolver.o
MODULES = read_file.mod
FC = gfortran
main.exe: $(OBJECTS)
$(FC) -o main $(OBJECTS)
solidsolver.o: $(MODULES) solidsolver.f90
$(FC) -c solidsolver.f90
%.mod: %.f90
$(FC) -c $<
%.o: %.f90
$(FC) -c $<
clean:
rm -f *.o *.mod main
我有一个名为 solidsolver.f90 的 Fortran 主程序和一个名为 read_mesh.f90
的模块。该模块包含两个子程序,用于主程序。我可以手动编译它们,但不能使用 makefile。我的 makefile 名为 makefile.makefile
,它给我一个错误:
make: *** No targets specified and no makefile found. Stop.
我确实需要一个以简洁的方式编写的 makefile,因为将来我的代码将成倍增长。这是生成文件:
OBJECTS = read_file.o solidsolver.o
MODULES = read_file.mod
.PHONY: clean
main.exe: $(MODULES) $(OBJECTS)
gfortran $(OBJECTS) -o main.exe
%.o: %.f90
gfortran -c $<
%.mod: %.f90
gfortran -c $<
clean:
rm -f $(OBJECTS) $(MODULES) main.exe
GNU make
正在按以下顺序查找 makefile(来自手册页):
[...] GNUmakefile, makefile, and Makefile, in that order.
要使用名为 makefile.makefile
的文件,您需要明确告诉 make 使用该(非标准)文件:
make -f makefile.makefile
亚历克斯是对的。但实际上makefile的内容是错误的。我将其更改如下并且有效:
OBJECTS = read_file.o solidsolver.o
MODULES = read_file.mod
FC = gfortran
main.exe: $(OBJECTS)
$(FC) -o main $(OBJECTS)
solidsolver.o: $(MODULES) solidsolver.f90
$(FC) -c solidsolver.f90
%.mod: %.f90
$(FC) -c $<
%.o: %.f90
$(FC) -c $<
clean:
rm -f *.o *.mod main