修改SPheno4.F90后编译报错:Control.F90命令未找到及Makefile求助
Alright, let's tackle this make error you're facing. I'll break down the issues and walk you through how to debug and fix them:
First, let's understand the critical error: "Control.F90: Command not found" (exit code 127)
Exit code 127 means your shell can't find the command it's trying to run. In this case, make is trying to execute Control.F90 directly like it's a shell command—which it's not! That tells me there's a mistake in the Makefile rule for building ../lib/libSPheno.a(Control.o).
Steps to fix this:
Preview the commands make wants to run
In yoursrcdirectory, run:make -nThis will print all the commands make intends to execute without actually running them. Look for the line that references
Control.oor../lib/libSPheno.a(Control.o)—you'll probably see something likeControl.F90instead of a proper Fortran compile command (likegfortran -c Control.F90 -o Control.o).Check the Makefile's compile rule for Control.o
Find the section in your Makefile that defines how to buildControl.o(or the rule for../lib/libSPheno.a(Control.o)). A correct rule should look something like this:../lib/libSPheno.a(Control.o): Control.F90 $(FC) $(FFLAGS) -c $< -o Control.o ar rcs ../lib/libSPheno.a Control.oOr if the Makefile uses pattern rules, it might have a generic rule for
.F90to.ofiles:%.o: %.F90 $(FC) $(FFLAGS) -c $< -o $@If the rule is missing the compiler command (
$(FC)) and just listsControl.F90as the command to run, that's exactly your problem.Verify compiler variables are set
Check the top of your Makefile for variables likeFC(Fortran compiler) andFFLAGS(compile flags). They should be defined, e.g.:FC = gfortran FFLAGS = -O2 -WallIf
FCis missing or incorrectly set, make won't know what compiler to use, leading to it trying to run the source file directly.
Next, the warning about "deterministic mode" for libSPheno.a
This warning is less critical—it's just telling you that the ar tool (used to create static libraries) is building the archive in deterministic mode (which is a good thing for reproducibility). If you want to suppress it, check your Makefile's ARFLAGS variable. It might need an update to match newer ar versions. For example:
ARFLAGS = rcsD # Add the -D flag for deterministic mode explicitly
Or if your ar uses long options:
ARFLAGS = rcs --deterministic
This warning won't stop your build, so fix the command-not-found error first.
General Makefile debugging tips for Fortran projects
Since you mentioned struggling to understand the Makefile, here are some go-to tools to help:
make -p: Prints all variables, rules, and implicit rules that make uses. This is great for checking if variables likeFCorARare correctly defined.make -d: Enables debug mode, which outputs every decision make makes (how it matches targets, resolves dependencies, etc.). It's verbose, but perfect for tracking down weird dependency issues.- Test commands manually: Once you identify the broken command from
make -n, run the correct version yourself (e.g.,gfortran -c Control.F90 -o Control.ofollowed byar rcs ../lib/libSPheno.a Control.o). If this works, you know the problem is definitely in the Makefile's rule syntax. - Check for module dependencies: Fortran relies heavily on
.modfiles (compiled module interfaces). If your modifiedSPheno4.F90uses modules fromControl.F90(or vice versa), make sure the dependency is listed in the Makefile—missing dependencies can lead to strange errors too.
内容的提问来源于stack exchange,提问作者Liberty

