Fortran function in a module not found by subrouti

2019-01-20 14:40发布

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.

1条回答
劳资没心,怎么记你
2楼-- · 2019-01-20 15:19

With the declaration of findkey inside the subroutine getNumber_Mesh() you are creating a local variable findkey 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.

查看更多
登录 后发表回答