我认为这个问题很明显,虽然我用谷歌搜索了它,但我找不到任何解决方案。我想拆分我的源代码以使其更易于维护。如何引用另一个文件中的模块?
问问题
5743 次
1 回答
5
我认为您正在寻找use
声明。例如,您可能有一个包含模块定义的源文件,大纲:
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
文件有点像头文件,但它是由编译器创建的。
稍后,当您链接程序时,您将需要模块和程序的目标文件。
于 2013-03-21T16:57:52.983 回答