如何在Fortran 95中包含来自不同文件的模块?

如何在Fortran 95中包含来自不同文件的模块?,fortran,fortran95,silverfrost-fortran,Fortran,Fortran95,Silverfrost Fortran,这个问题很明显,我想,虽然我在谷歌上搜索了一下,但我找不到任何解决办法。我想拆分我的源代码,以使其更易于维护。如何引用另一个文件中的模块?我想您正在寻找use语句。例如,您可能有一个包含模块定义的源文件outline: module abstract_types implicit none ! declarations contains ! procedure definitions end module abstract_types program hello_

这个问题很明显,我想,虽然我在谷歌上搜索了一下,但我找不到任何解决办法。我想拆分我的源代码,以使其更易于维护。如何引用另一个文件中的模块?

我想您正在寻找
use
语句。例如,您可能有一个包含模块定义的源文件outline:

module abstract_types
    implicit none
    ! declarations
  contains
    ! procedure definitions
end module abstract_types 
program hello_there
    use abstract_types
    implicit none
    ! declarations
    ! executable statements
end program hello_there
然后,在另一个源文件中,使用模块的程序outline:

module abstract_types
    implicit none
    ! declarations
  contains
    ! procedure definitions
end module abstract_types 
program hello_there
    use abstract_types
    implicit none
    ! declarations
    ! executable statements
end program hello_there
注:

  • 任何
    use
    语句都位于
    implicit
    语句之前

  • use
    语句按名称引用模块

在编译时,确保在编译程序源文件之前先编译模块源文件;在编译时(不是在链接时),编译器将查找模块文件(通常称为
mod
文件),以满足
use
语句中对模块的引用。
mod
文件有点像头文件,但它是由编译器创建的


稍后,当您链接程序时,您将需要模块和程序的目标文件。

@High Performance Mar:您如何指明mod文件所在的编译器?