本文介绍了fortran中的多定义链接错误(ifort-gfortran)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Well, I've this problem (the description is long, but I think it is easy to solve) . I've three files:

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

nrtype.f90, which have some stupid definitions, but it is used by the following files:

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,这是工作的一部分:

LUd.f90, which makes part of the work:

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的文件,负责其他工作:

A file called FrontBackSub.f90, which does the other part of the work:

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:

But, the issue comes during compilation, with ifort nrtype.f90 FrontBackSub.f90 LUd.f90 FrontBackSub.f90 main.f90 i've got:

/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:

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

So, it says that the functions (it is plural because when I add new functions the issue expand to them) in FrontBackSub.f90 are defined several times which, clearly, the are not.

我看不到的问题在哪里?

Where is the problem that I can't see?

感谢您的时间伙伴.

推荐答案

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

Why do you have the source FrontBackSub.f90 two times in the compile command? Just don't do that.

这篇关于fortran中的多定义链接错误(ifort-gfortran)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 13:32