好吧,我有这个问题(描述很长,但是我认为很容易解决)。我有三个文件:

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中的函数(它是复数的,因为当我添加新函数时问题会扩展到它们)被定义了好几次,而显然没有。

我看不到的问题在哪里?

感谢您的时间朋友。

最佳答案

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

关于linker - fortran中的多定义链接错误(ifort-gfortran),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20059177/

10-11 22:59