fortran中的多重定义链接错误(ifort - gfortran)

时间:2013-11-18 22:21:42

标签: linker fortran gfortran intel-fortran

嗯,我有这个问题(描述很长,但我觉得很容易解决)。我有三个文件:

nrtype.f90,它有一些愚蠢的定义,但它被以下文件使用:

module nrtype
    integer, parameter :: I4B = SELECTED_INT_KIND(9)
    integer, parameter :: I2B = SELECTED_INT_KIND(4)
    integer, parameter :: I1B = SELECTED_INT_KIND(2)
    integer, parameter :: SP = KIND(1.0)
    integer, parameter :: DP = KIND(1.0D0)
endmodule nrtype

LUd.f90,这是工作的一部分:

module descomposicionLU
    use nrtype

    implicit none

contains

subroutine LUd(A, LU, bk)
    implicit none

    real(DP), intent (in), dimension(:,:)                 :: A
    real(DP), intent (out), dimension(:,:)                :: LU
    integer(I2B), dimension(size(A,1),2)                  :: bk

        <more code that doesn't worth to mention>

endsubroutine LUd

<more code that doesn't worth to mention>

endmodule descomposicionLU

一个名为FrontBackSub.f90的文件,它执行工作的另一部分:

module FrontBack

    use nrtype

    implicit none

contains

function FrontSLU(A,B) result (X)
    implicit none
    real(DP), dimension(:,:), intent (in)       :: A, B
    real(DP), dimension(size(B,1),size(B,2))    :: X

     <more code>

endfunction FrontSLU

endmodule FrontBack

最后是main.f90,这是这样的:

program main
    use descomposicionLU
    use FrontBack

    implicit none

    integer, parameter                      :: N=3
    real(DP), dimension(N,N)                :: MA, MLU
    integer(I2B), dimension(N,2)            :: Vbk


    MA(1,:)=(/1.0,   7.0,     11.0/)
    MA(2,:)=(/14.0,  24.0,    19.0/)
    MA(3,:)=(/7.0,   8.0,     9.0/)

    call LUd(MA, MLU, Vbk)

endprogram main

但是,问题出现在编译过程中,ifort nrtype.f90 FrontBackSub.f90 LUd.f90 FrontBackSub.f90 main.f90我得到了:

/tmp/ifortbW2y7D.o: In function `frontback._':
FrontBackSub.f90:(.text+0x0): multiple definition of `frontback._'
/tmp/ifortVQdBCN.o:FrontBackSub.f90:(.text+0x0): first defined here
/tmp/ifortbW2y7D.o: In function `frontback_mp_frontslu_':
FrontBackSub.f90:(.text+0x10): multiple definition of `frontback_mp_frontslu_'
/tmp/ifortVQdBCN.o:FrontBackSub.f90:(.text+0x10): first defined here
/tmp/ifortbW2y7D.o: In function `frontback_mp_backs_':
FrontBackSub.f90:(.text+0x460): multiple definition of `frontback_mp_backs_'
/tmp/ifortVQdBCN.o:FrontBackSub.f90:(.text+0x460): first defined here

或者更清楚,gfortran nrtype.f90 FrontBackSub.f90 LUd.f90 FrontBackSub.f90 main.f90

/tmp/ccpZnjOp.o: In function `__frontback_MOD_backs':
FrontBackSub.f90:(.text+0x0): multiple definition of `__frontback_MOD_backs'
/tmp/ccsr4QjQ.o:FrontBackSub.f90:(.text+0x0): first defined here
/tmp/ccpZnjOp.o: In function `__frontback_MOD_frontslu':
FrontBackSub.f90:(.text+0x582): multiple definition of `__frontback_MOD_frontslu'
/tmp/ccsr4QjQ.o:FrontBackSub.f90:(.text+0x582): first defined here
collect2: error: ld returned 1 exit status

所以,它说FrontBackSub.f90中的函数(它是复数,因为当我添加新函数时问题扩展到它们)被定义了几次,显然,它们不是。

我看不到的问题在哪里?

感谢您的朋友们。

1 个答案:

答案 0 :(得分:6)

为什么在编译命令中有两次源FrontBackSub.f90?只是不要这样做。