Fortran编译错误 - 未定义的引用

use*_*052 8 fortran

我正在尝试编译一个使用一堆模块的fortran程序.编译时我得到一个错误,这让我发疯了.该错误是由添加一个子例程引起的,当我尝试重新编译程序时发生:

主程序包含以下两行:

-

call read_step(nStepOne,molOne)
call read_step(nStep,mol)
Run Code Online (Sandbox Code Playgroud)

-

这是调用文件"fileio.f90"子程序中的一种:

-

subroutine read_step(n,tape)

implicit none

integer, intent(in) :: tape
integer, intent(out) :: n

character(len=6) :: dum

rewind(tape)
read (tape,*)
read (tape,*) dum, n
rewind(tape)
return
!
end subroutine read_step
Run Code Online (Sandbox Code Playgroud)

-

当我尝试编译它时,出现以下错误:

ifort -o SpIdMD.x *.o -static-intel -openmp 
SpIdMD.o: In function `MAIN__':
SpIdMD.f90:(.text+0x3b2): undefined reference to `read_step_'
SpIdMD.f90:(.text+0x3c5): undefined reference to `read_step_'
make: *** [SpIdMD.x] Error 1
Run Code Online (Sandbox Code Playgroud)

在同一个模块中对子程序的其他调用没有给出任何错误,我只是看不到对"旧子程序"的调用与我刚刚创建的那个之间的任何区别.

这些"旧子程序"中的一个没有任何抱怨的例子是:

在主程序中:

call get_dim(n_atom,nSnap,mol)
Run Code Online (Sandbox Code Playgroud)

在fileio.f90中:

subroutine get_dim(n,n_snap,tape)

implicit none

integer,intent(in) :: tape
integer,intent(out) :: n, n_snap
integer :: m

rewind(tape)
read (tape,*,err=1,end=2) n
rewind(tape)

m = 0
do while (.true.)
   read (tape,*,err=1,end=3)
   m = m +1
end do
3   n_snap = m/(n + 2)
if (m.ne.(n_snap*(n + 2))) stop  'unexpected end of input file'

rewind(tape)

return
!
1   stop 'error in input file'
2   stop 'unexpected end of input file'
end subroutine get_dim
Run Code Online (Sandbox Code Playgroud)

我完全不知道为什么会这样.如果有人能帮我解决这个噩梦,我将不胜感激.谢谢!

Ian*_*anH 8

如果子例程read_step的定义在模块中,那么您忘记将该模块的USE语句添加到主程序的顶部,或者模块中的相关过程不是PUBLIC.

使用该编译器(以及其他一些编译器),模块过程的链接器名称通常由模块名称后跟" mp "(大小写可能不同)后跟过程名称组成,其中包含各种数量的前导和尾随下划线.您的链接器错误没有任何"mangling",这表明在使用过程引用编译作用域时,编译器不认为该过程是模块过程.