make finds fortran 77 files but not fortran 90 files

emptypenny

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?

downhillFromHere

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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

可以查找fortran 77文件,但不能查找fortran 90文件

来自分类Dev

如何使FORTRAN 77读取输入?

来自分类Dev

Fortran 90函数返回指针

来自分类Dev

Fortran 90和MPI错误

来自分类Dev

Fortran 90-阅读格式

来自分类Dev

FORTRAN 90奇怪的通话声明

来自分类Dev

Fortran 90和MPI错误

来自分类Dev

How to update Fortran 77 programs to more modern Fortran to improve readability?

来自分类Dev

将Fortran 77转换为Fortran 95

来自分类Dev

Fortran 77实数到整数舍入方向?

来自分类Dev

在Fortran 77中重命名文件

来自分类Dev

在Fortran77中删除重复的行

来自分类Dev

用 Julia 编译 Fortran77

来自分类Dev

Fortran 77 Do Loop 块说明

来自分类Dev

如何使用 Fortran 77 计算矩阵的对数?

来自分类Dev

Fortran 90数据语句不会覆盖数据

来自分类Dev

Fortran 90/95中的广播阵列乘法

来自分类Dev

如何在Fortran 90中刷新stdout?

来自分类Dev

Fortran 90 intent(in)用于递归函数

来自分类Dev

Fortran90中的变量相关格式

来自分类Dev

Fortran 90可分配的auto(?)分配

来自分类Dev

LAPACK过程的数值精度不足(Fortran 90)?

来自分类Dev

解释fortran 90中的内存地址

来自分类Dev

实数据类型fortran 90

来自分类Dev

Fortran 90中的'==','>'或'<'是否有效?

来自分类Dev

使用Fortran 90循环评估功能

来自分类Dev

如何在Fortran 90中刷新stdout?

来自分类Dev

减少 Fortran 90 中数组的大小

来自分类Dev

从fortran90(或gfortran)逆向翻译为ratfor90?