在同一模块的子例程中找不到模块中的Fortran函数 [英] Fortran function in a module not found by subroutine in the same module

查看:173
本文介绍了在同一模块的子例程中找不到模块中的Fortran函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Fortran90中编写一个模块,主要是我在模块内部定义了一个函数,以及使用该函数的子例程.这是该模块的摘录

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.

推荐答案

在子例程getNumber_Mesh()中使用findkey的声明,您将创建一个隐藏该函数的局部变量findkey.

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.

这篇关于在同一模块的子例程中找不到模块中的Fortran函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆