gfortran 中对 `sleep` 和 `sizeof` 指令的未定义引用

Undefined reference to `sleep` and `sizeof` instrinsics in gfortran

gfortran 找不到 GNU Fortran 提供的内部函数(sleep、sizeof、...):

undefined reference to `sleep_'

我已经从 MinGW 安装管理器安装了 mingw32-base 和 mingw32-gcc-fortran。

即使使用这个简单的代码也会出现此问题:

program p
implicit none

    call SLEEP(1)

end program p

命令:$ gfortran.exe -std=f2008 .\test.f08

事实上它适用于 $ gfortran.exe .\test.f08。但是,它应该与前一个一起使用。

您使用的程序不是标准 Fortran。当您通过 -std=f2008 明确请求标准 Fortran 时,编译器将不会 link 非标准内部过程,因为它们不在您明确请求的标准中。

当您使用

intrinsic sleep

您收到更明确的错误消息:

intrinsic sleep
               1
Error: The intrinsic ‘sleep’ declared INTRINSIC at (1) is not available
in the current standard settings but a GNU Fortran extension. Use an appropriate 
‘-std=*’ option or enable ‘-fall-intrinsics’ in order to use it.

因此,如消息所述,您可以使用 -fall-intrinsics 启用非标准内部过程。