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

时间:2017-12-18 05:38:22

标签: compiler-errors fortran gnu gfortran compiler-flags

I'm trying to compile a Fortran application using gfortran, linking with Intel MKL libraries.

undefined reference to `dacosd_'

There is a acos or acosd (inverse cosine in degree), I'm almost there but I can't compile using -fall-intrinsics or -dec-math flag, as instructed in the manual, because it all yields the same error.

Where have I got it wrong, and how can I compile this?

The gfortran version I'm using is 5.4.1.

1 个答案:

答案 0 :(得分: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功能,以保持便携性。