Oop 同一模块中的子例程找不到模块中的Fortran函数
我正在用Fortran90编写一个模块,主要是在模块内部定义了一个函数,以及一个使用该函数的子程序。这是本模块的摘录Oop 同一模块中的子例程找不到模块中的Fortran函数,oop,fortran,gfortran,Oop,Fortran,Gfortran,我正在用Fortran90编写一个模块,主要是在模块内部定义了一个函数,以及一个使用该函数的子程序。这是本模块的摘录 module Mesh_io implicit none private contains integer function findkey ( ) content of this function end function subroutine getNumber_Mesh () integer :: findkey content
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\u Mesh()
中的findkey声明,您正在创建一个隐藏函数的局部变量findkey
对于模块,不需要声明函数(模块函数)的返回值。简单地删除声明就可以了 谢谢你的回答@Alexander Vogt。模块的使用对我来说真的很新。这个反馈真的很有帮助。由于链接器找不到函数
findkey
,也找不到所需的findkey
,因此getNumber\u Mesh
中的其他内容可能意味着它声明的是一个外部函数,而不是局部变量。相关