即使使用“-dec-math”,gfortran 也会给出对“dacosd_”的未定义引用

gfortran gives undefined reference to `dacosd_` even with `-dec-math`

我正在尝试使用 gfortran 与英特尔 MKL 库链接来编译 Fortran 应用程序。

undefined reference to `dacosd_'

有一个 acosacosd(度的反余弦),我快到了,但我无法使用 -fall-intrinsics-dec-math 标志进行编译,按照手册中的说明,因为它都会产生相同的错误。

我哪里弄错了,我该如何编译?

我使用的 gfortran 版本是 5.4.1。

正如 RussF 评论的那样,这些非标准扩展函数包含在 gfortran 7 及更高版本中。你需要一个更新的版本。此外,正确的标志是 -fdec-math,而不是 -dec-math

intrinsic dacosd

print *, dacosd(0.5d0)
end

编译为:

> gfortran-6 -fdec-math dacosd.f90 
gfortran-6: error: unrecognized command line option ‘-fdec-math’; did you mean ‘-ffast-math’?
> gfortran-7 -fdec-math dacosd.f90
> ./a.out 
   60.000000000000007     

您可以通过转换轻松地进行相同的计算

double precision, parameter :: pi = acos(-1.d0)
print *, acos(0.5d0)*180/pi
end

或者您可以通过这种方式定义自己的 (d)acosd 函数,以保持可移植性。