gpt4 book ai didi

error-handling - 我使用 Simply Fortran,但不能在那里包含模块

转载 作者:行者123 更新时间:2023-12-03 08:37:58 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





The mysterious nature of Fortran 90 modules

(1 个回答)


1年前关闭。




我在名为“Simply Fortran”的系统中编写了以下 Fortran 代码:

program math2 
use prec, only: print_kind_info
implicit none
call print_kind_info
end program math2

module prec

implicit none
integer, parameter :: dp = selected_real_kind(P=10,R=30)
integer, parameter :: sp = selected_real_kind(P=5,R=15)
integer, parameter :: dp_alt = kind(0.d0)
public :: dp, sp, print_kind_info
private

contains

! Subroutine comes here

subroutine print_kind_info()
real(sp) :: sing_prec
real(dp) :: double_prec

print*,'Single precision is kind ',sp
print*,'Double precision is kind ',dp
print*,'Kind of double precision number is ',dp_alt

end subroutine print_kind_info

end module prec
但是,找不到我称之为“prec”的模块。更准确地说,错误消息如下:
 use prec, only: print_kind_info
1
Fatal Error: Can't open module file 'prec.mod' for reading at (1): No such file or directory
compilation terminated.
Error(E42): Last command making (build\prec.o) returned a bad status
Error(E02): Make execution terminated

* Failed *
我必须做什么才能正确识别模块(参见上面的代码)?它在文件大纲中被识别,但它不在“模块”文件夹中。我真的没有计划在这里做什么。此外,我对 Makefile 环境没有经验(我不熟悉这种类似 BASHrc 的东西)。

最佳答案

简单地说:问题是编译器不知道模块prec.mod at 在主程序之后定义,但已在主程序中使用。
所以首先定义模块,然后定义主程序。
最好将模块放在单独的文件中,将主程序放在另一个文件中并编译它们(以正确的顺序)并将所有内容链接在一起。

关于error-handling - 我使用 Simply Fortran,但不能在那里包含模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64898751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com