This question already has an answer here:
I am writing a module in Fortran90, Mainly I defined a function inside the module, and a subroutine that uses the function. Here's an excerpt of the module
module Mesh_io
implicit none
private
contains
integer function findkey ( )
content of this function
end function
subroutine getNumber_Mesh ()
integer :: findkey
content of the routine
end subroutine getNumber_Mesh
end module
When compiling I get the following output:
objects/Main.o: In function `__mesh_io_MOD_getnumber_mesh':
Main.f90:(.text+0x9e): undefined reference to `findkey_'
As you can see the function is contained in the module, but for some reason the compiler can not find it.
With the declaration of findkey inside the subroutine
getNumber_Mesh()
you are creating a local variablefindkey
that hides the function.With modules, it is not required to declare the return value of functions (of module functions). Simply removing the declaration should do the trick.