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

2024-03-24

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

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被定义了好几次,但很明显,它们没有被定义。

我看不到的问题在哪里?

感谢各位朋友的宝贵时间。


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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐