You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Fortran90模块中子程序无法找到同模块内函数的编译问题

Undefined Reference to findkey_ in Fortran 90 Module: Fix & Explanation

Got it, let's break down why this linker error is happening even though your function and subroutine live in the same module, and how to fix it right away.

The root issue here is variable shadowing in your getNumber_Mesh subroutine:

  • You added the line integer :: findkey inside the subroutine, which declares a local integer variable with the exact same name as your module's findkey function.
  • In Fortran, local variables always take priority over module-level entities with matching names. This means the compiler thinks you're referring to this integer variable instead of the function. When linking, it can't find the findkey_ symbol because the subroutine isn't actually calling the module's function anymore.

The Fix

Just delete the integer :: findkey line from your getNumber_Mesh subroutine. Since both the function and subroutine are part of the same module, the subroutine has direct access to the findkey function—no need to re-declare it.

Here's the corrected module code:

module Mesh_io
    implicit none
    private
contains
    integer function findkey ()
        ! content of this function
    end function

    subroutine getNumber_Mesh ()
        ! Removed the shadowing integer declaration here
        ! content of the routine
        ! Now you can call findkey() directly, e.g.:
        ! my_integer = findkey()
    end subroutine getNumber_Mesh
end module

Quick Heads-Up

This kind of name clash is a common Fortran gotcha. Always double-check that your local variable names don't overlap with functions, subroutines, or other module-level entities—shadowing can lead to confusing errors like this one.

内容的提问来源于stack exchange,提问作者Andres Valdez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:15:11