GNU Fortran - 函数“dcosd”没有隐式类型

问题描述 投票:0回答:1

我是 Fortran 编码的新手,也是 GNU Fortran 和 Code::Blocks 的新手。

我已经在Win10上安装了codeblocks-20.03mingw-setup,现在尝试从头开始运行这段代码:

program hello

implicit none

  real :: x = 0.0
  x = dcosd(x)

  write(*,*) x

end program

但由于某种原因,我收到此构建消息:

C:\...\Hello_Test\main.f90|7|Error: Function 'dcosd'  has no IMPLICIT type|

如果我删除该行

implicit none
我会收到此消息:

C:\...\Hello_Test\main.f90|5|undefined reference to `dcosd_'|

我非常确定 DCOSD 是 gFortran 中的一种标准函数。我尝试了一些“隐式类型”问题的解决方案,但没有结果。我认为解决方案对于有经验的人来说应该是非常明显的,但我却无法理解。

fortran mingw codeblocks gfortran
1个回答
0
投票

GCC 版本 7 已经很旧了。

dcosd()
在您的代码中被版本 10 及更高版本识别(我测试了 10、11、12 和 13)。

但是,使用这些更高版本,您将遇到另一个错误

    6 |   x = dcosd(x)
      |            1
Error: ‘x’ argument of ‘dcosd’ intrinsic at (1) must be double precision

这将由

double precision :: x = 0
修复。

或者您可以将

dcosd()
更改为通用
cosd()
。在这种情况下,将使用单精度版本,并且代码将在 GCC 版本 10 及更高版本中使用 wither
real
double precision
进行编译。

© www.soinside.com 2019 - 2024. All rights reserved.