I am having problems compiling a mixed C++/fortran90 code using make. If I instead use a fortran77 code for the subroutine, I have no problems compiling.
The structure of the file system:
~/src/working/:
main.cpp
Makefile
~/src/lib/:
f77library.f
f90library.f90
cpplibrary.cpp
~/src/headers/:
cpplibrary.h
The makefile looks like the following:
VPATH = ../headers/:../lib/
F77 = gfortran
FC = gfortran
CXX = g++
FCFLAGS = -I/home/user/src/headers/ #These may be redundant with VPATH
FFLAGS = -I/home/user/src/headers/
CXXFLAGS = -I/home/user/src/headers/
main77 = main.o f77library.o cpplibrary.o
main90 = main.o f90library.o cpplibrary.o
main77 : $(main77)
$(CXX) -o main77 $(main77) -lgfortran
main90 : $(main90)
$(CXX) -o main90 $(main90) -lgfortran
main77.o : main77.cpp cpplibrary.h
main90.o : main90.cpp cpplibrary.h
cpplibrary : cpplibrary.cpp cpplibrary.h
f77library : f77library.f
f90library : f90library.f90
Each fortran file contains exactly the same subroutines and each is a standalone file. If I do the compiling by hand it works just fine, e.g.,
gfortran -c ../lib/f90library.f90
g++ -c ../lib/cpplibrary.cpp -I../headers/
g++ -c main90.cpp -I../headers/
g++ -o main90 main90.o f90library.o cpplibrary.o
When I compile the f77 using the makefile: make main77
it compiles fine. When I try make main90
however, I get the following error message
g++ -o main90 main90.o f90library.o cpplibrary.o -lgfortran
g++: f90library.o: No such file or directory
In short, everything is identical between the f90 and f77 versions, and there should be no compilation errors. Why can't make
recognize that there is a .f90 file it needs to compile in the lib directory?
Apparently, Make does not provide an implicit rule for compiling .f90 files. But you could still achieve what you want, e.g., by adding a pattern rule
%.o: %.f90
$(FC) $(FFLAGS) -c $<
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句