I'm a newbie in Fortran coding also in GNU Fortran and Code::Blocks.
I've installed codeblocks-20.03mingw-setup on Win10 and now trying to run this piece of code from scratch:
program hello
implicit none
real :: x = 0.0
x = dcosd(x)
write(*,*) x
end program
But in some reason I'm getting this Build message:
C:\...\Hello_Test\main.f90|7|Error: Function 'dcosd' has no IMPLICIT type|
If I delete the line implicit none
I get this message instead:
C:\...\Hello_Test\main.f90|5|undefined reference to `dcosd_'|
I'm pretty sure DCOSD is kind a standard functoun in gFortran. I tried some some solutions for "IMPLICIT type" problem, but with no result. I think the solution shuld be pretty obvious for experienced people but it eludes me.
First to clarify, dcosd()
is not a standard intrinsic function in Fortran. It used to be available as an extension to the standard by some compilers. Fortran 2023 brings the generic version cosd()
as a standard intrinsic function, but modern Fortran standards do not really work too much with the specific functions like dcosd()
and it has not been made standard.
GCC version 7 is quite old. dcosd()
is recognized in your code by versions 10 and later (I tested 10, 11, 12 and 13). For versions 7-9 you need the option -fdec-math
, mentioned by francescalus in the first comment, to enable the non-standard extension.
However, with these later versions or with the -fdec-math
option you will get another error
6 | x = dcosd(x)
| 1
Error: ‘x’ argument of ‘dcosd’ intrinsic at (1) must be double precision
That will be fixed by double precision :: x = 0
.
Or you can change dcosd()
to the generic cosd()
. In that case the single precision version will be used and the code will compile with either real
or double precision
in GCC version 10 and later.