同一模块中的子例程找不到模块中的 Fortran 函数
Fortran function in a module not found by subroutine in the same module
我在写一个Fortran90的模块,主要是在模块内部定义了一个函数,以及一个使用该函数的子程序。这是模块的摘录
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
编译时得到以下输出:
objects/Main.o: In function `__mesh_io_MOD_getnumber_mesh':
Main.f90:(.text+0x9e): undefined reference to `findkey_'
如您所见,函数包含在模块中,但由于某种原因编译器找不到它。
通过在子例程 getNumber_Mesh()
中声明 findkey,您将创建一个隐藏该函数的局部变量 findkey
。
对于模块,不需要声明函数(模块函数)的 return 值。只需删除声明就可以解决问题。
我在写一个Fortran90的模块,主要是在模块内部定义了一个函数,以及一个使用该函数的子程序。这是模块的摘录
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
编译时得到以下输出:
objects/Main.o: In function `__mesh_io_MOD_getnumber_mesh':
Main.f90:(.text+0x9e): undefined reference to `findkey_'
如您所见,函数包含在模块中,但由于某种原因编译器找不到它。
通过在子例程 getNumber_Mesh()
中声明 findkey,您将创建一个隐藏该函数的局部变量 findkey
。
对于模块,不需要声明函数(模块函数)的 return 值。只需删除声明就可以解决问题。