【问题标题】:"Can't open module file 'types.mod'" when compiling a main.f90 program编译 main.f90 程序时“无法打开模块文件 'types.mod'”
【发布时间】:2021-11-01 11:46:19
【问题描述】:

快速运行:

  • 我是 fortran 新手

  • 我在 Windows 机器上

  • 使用 sublime 编辑赋值 fortran 代码

  • 分配包含一个 main.f90 文件(请参见下图该文件的代码)

  • 这个 main.f90 代码调用了 3 个不同的模块:“types”和“analytic_functions”,以及 '欧拉公式'

  • 每当我尝试在 Windows 命令提示符中运行命令 gfortran main.f90 时,都会出现以下错误:

     Fatal Error: Can't open module file 'types.mod' for reading at (1): No such file or directory compilation terminated. 
    

我该如何解决这个问题?我们将不胜感激所有帮助。

这是 main.f90 代码:

module read_write
use types
use analytic_functions, only : second_derivative_f
use euler_formulas, only : euler_3points
implicit none

private
public read_input, write_derivatives

contains

我不知道这是否有帮助,但这里是“types.f90”代码:

module types
! The iso_fortran_env is an intrinsic module that should already be
! inside of your compiler
use iso_fortran_env
implicit none
integer, parameter :: sp = REAL32 !< single precision kind
integer, parameter :: dp = REAL64 !< double precision kind
integer, parameter :: qp = REAL128!< quadruple precision kind
real(dp), parameter :: pi=acos(-1.0_dp)!< &pi; = 3.141592...
end module types

【问题讨论】:

    标签: windows fortran command gfortran


    【解决方案1】:

    注意:这些 .mod 文件或多或少类似于 C 头文件,它们允许编译器在编译时检查类型,这在 Fortran 77 从多个源文件编译时通常是不可能的。它们是在您编译模块时创建的。

    因此,您必须首先编译模块。请注意,要编译和链接 main.f90,您还必须将目标文件传递给 gfortran,否则链接器将无法解析对这些模块中函数的引用。

    gfortran -c types.f90
    gfortran -c analytic_functions.f90
    gfortran -c euler_formulas.f90
    gfortran main.f90 types.obj analytic_functions.obj euler_formulas.obj
    

    gfortran 编译器也可以一次编译所有文件,但您必须按特定顺序传递文件:如果程序或模块 B 使用模块 A,则 B.f90 必须在 之后命令行上的 A.f90。这是编译器在使用 .mod 文件时查找它们所必需的。

    gfortran types.f90 analytic_functions.f90 euler_formulas.f90 main.f90
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-10
      • 1970-01-01
      • 2016-01-05
      • 2012-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多