Search code examples
compiler-errorsfortrangnugfortrancompiler-flags

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


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.


Solution

  • As RussF commented, these non-standard extension functions are included in gfortran 7 and later. You need a newer version. Also, the correct flag is -fdec-math, not -dec-math.

    intrinsic dacosd
    
    print *, dacosd(0.5d0)
    end
    

    compile as:

    > 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     
    

    You can easily do the same computation with a conversion

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

    or you can define your own (d)acosd function this way, to stay portable.