2016-03-03 116 views
0

错误消息:的Fortran链接错误:未定义使用参考子模块

mod_matrices.o:(.data+0x1790): undefined reference to `allocator_rank_2_sub_' 

模块mMatrices(在mod_matrices.f08)调用函数allocator_rank_2_sub这是在一个子模块smAllocations(在mod_sub_matrices_allocators.f08)。代码在将模块mMatrices分解为模块和子模块之前工作。

模块:

module mMatrices 
    use mPrecisionDefinitions, only : ip, rp  
    implicit none 

    type :: matrices 
     real (rp), allocatable :: A (: , :), AS (: , :), ASAinv (: , :) 
    contains 
     private 
     procedure, nopass, public :: allocator_rank_2 => allocator_rank_2_sub 
     procedure, public   :: construct_matrices => construct_matrices_sub 
    end type matrices 

    private :: allocator_rank_2_sub 
    private :: construct_matrices_sub 

    interface 
     subroutine allocator_rank_2_sub (array, rows, cols) 
      use mPrecisionDefinitions, only : ip, rp 
      real (rp), allocatable, intent (out) :: array (: , :) 
      integer (ip),   intent (in) :: rows, cols 
     end subroutine allocator_rank_2_sub 
    end interface 

    contains 
     subroutine construct_matrices_sub (me, ints, mydof, measure) 
      ... 
       call me % allocator_rank_2 (me % A, m, mydof) 
      ... 
     end subroutine construct_matrices_sub 
end module mMatrices 

子模块:

submodule (mMatrices) smAllocations 
    contains  
     module subroutine allocator_rank_2_sub (array, rows, cols) 
      ... 
     end subroutine allocator_rank_2_sub 
end submodule smAllocations 

经由化妆编译:

ftn -g -c -r s -o mod_precision_definitions.o mod_precision_definitions.f08 
... 
ftn -g -c -r s -o mod_matrices.o mod_matrices.f08 
... 
ftn -g -c -r s -o mod_sub_matrices_allocators.o mod_sub_matrices_allocators.f08 
... 
ftn -g -c -r s -o lsq.o lsq.f08 
ftn -g -o lsq lsq.o --- mod_matrices.o --- mod_precision_definitions.o --- mod_sub_matrices_allocators.o --- 
mod_matrices.o:(.data+0x1790): undefined reference to `allocator_rank_2_sub_' 
make: *** [lsq] Error 1 

`生成文件”

# Main program depends on all modules 
$(PRG_OBJ) : $(MOD_OBJS) 

# resolve module interdependencies 
... 
mod_matrices.o    : mod_precision_definitions.o mod_parameters.o mod_intermediates.o 
mod_sub_matrices_allocators.o : mod_matrices.o 
... 
的最后部分

本机:克雷XC30

编译器:Fortran的82年2月5日

的问题:什么需要解决吗?

掺入@ IanH的fix

校正的代码片断:

interface 
    MODULE subroutine allocator_rank_2_sub (array, rows, cols) 
     use mPrecisionDefinitions, only : ip, rp 
     real (rp), allocatable, intent (out) :: array (: , :) 
     integer (ip),   intent (in) :: rows, cols 
    end subroutine allocator_rank_2_sub 
end interface 

回答

2

在模块的规范部分allocator_rank_2_sub接口块缺少MODULE前缀。这意味着它指定了一个外部过程,而不是指定的独立模块过程。然后链接器抱怨说它找不到这样的外部过程。

将MODULE前缀添加到接口主体中的子例程语句中。