"make: *** No rule to make target '.f90', needed by '.o'. Stop." - Decoding the Fortran Compilation Error
Have you encountered the cryptic error message "make: *** No rule to make target '.f90', needed by '.o'. Stop." while attempting to compile your Fortran code? This error indicates a fundamental problem in your build process, specifically, that the makefile (the file that guides the compilation) doesn't know how to create the necessary Fortran source file (.f90
) from your existing code. This article will help you understand the error, debug it, and get your Fortran code compiling smoothly.
Understanding the Error:
- make: The "make" command is a tool that automates the compilation and linking process of your code. It reads instructions from a "makefile".
- .f90: This refers to a Fortran source code file.
- .o: This represents an "object file" which is a compiled version of your Fortran code, ready for linking.
The error means that the makefile you are using lacks the necessary rules to turn your Fortran source code into a usable object file. The makefile needs instructions on how to compile your Fortran code with the correct compiler flags and options.
Scenario and Code:
Let's consider a simple example:
# makefile
all: myprogram
myprogram: myprogram.o
g++ myprogram.o -o myprogram
myprogram.o: myprogram.cpp
g++ -c myprogram.cpp
In this example, the makefile attempts to create a program called myprogram
from a C++ source file myprogram.cpp
. However, if we replace myprogram.cpp
with myprogram.f90
(a Fortran source file), the makefile won't be able to compile it.
Analysis and Solution:
The key to resolving this error lies in understanding that the makefile needs instructions for both the compilation of your Fortran source code and the linking process. Here's how to modify the makefile to handle Fortran:
# makefile
all: myprogram
myprogram: myprogram.o
g++ myprogram.o -o myprogram
myprogram.o: myprogram.f90
gfortran -c myprogram.f90
Important Points:
- gfortran: This is the GNU Fortran compiler. If you use a different Fortran compiler, replace
gfortran
with the appropriate command. - Compiler Flags: You may need to add compiler flags to
gfortran
depending on your project's requirements. - Linking Libraries: If your program relies on external libraries, you'll need to link them in the
myprogram
rule.
Additional Value:
To further troubleshoot this error, consider these tips:
- Check your makefile: Ensure the makefile correctly references your Fortran files and uses the appropriate compiler.
- Compiler Path: Confirm that your Fortran compiler is installed and accessible from the command line.
- File Extensions: Ensure your Fortran source files have the correct extension (
.f90
,.f
, or.F90
). - Error Messages: Pay close attention to any other error messages that accompany the "No rule to make target" error. These can provide additional clues about the cause of the problem.
Resources and References:
- GNU Fortran Documentation: https://gcc.gnu.org/onlinedocs/gfortran/
- Make Manual: https://www.gnu.org/software/make/manual/make.html
By understanding the error and making the necessary adjustments to your makefile, you can successfully compile and run your Fortran programs.