Fortran编译错误 - 未定义的引用 [英] Fortran compilation error - undefined reference

查看:1446
本文介绍了Fortran编译错误 - 未定义的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译一个使用了一堆模块的fortran程序。我编译时遇到错误,这让我发疯。这个错误是由于增加了一个子程序而产生的,当我尝试重新编译这个程序时:

主程序包含这两行:


$ p $ call read_step(nStepOne,molOne)
call read_step(nStep, mol)

-



这是调用文件fileio.f90中的一个子例程:



-

 子程序read_step(n,磁带)

隐含无

整数,意图(in)::磁带
整数,意图(输出): :n

字符(len = 6):: dum

倒带(磁带)
读取(磁带,*)
读取(磁带,* )dum,n
倒带(磁带)
返回

结束子程序read_step

-



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

  ifort -o SpIdMD.x * .o -static -intel -openmp 
SpIdMD.o:在函数`MAIN__'中:
SpIdMD.f90 :( .text + 0x3b2):对`read_step_'的$ undefined引用
SpIdMD.f90 :( .text + 0x3c5):对`read_step_'的未定义引用
make:*** [SpIdMD.x]错误1

调用同一模块中的子例程没有发生任何错误,我只是没有看到对旧子例程的调用和我刚创建的那个之间的区别。



这些旧子程序之一的例子不给任何抱怨,它是:

在主程序中: / p>

  call get_dim(n_atom,nSnap,mol)

在fileio.f90中:

$ p $子程序get_dim(n,n_snap,tape)

隐含无

整数,意图( in):: tape
整数,意图(出):: n,n_snap
整数:: m

倒带(磁带)
读取(磁带,*, err = 1,end = 2)n
倒带(磁带)

m = 0
同时(.true。)
读取(磁带,*,err = 1,end = 3)
m = m +1
end do
3 n_snap = m /(n + 2)
if(m.ne.(n_snap *(n + 2)))停止输入文件的意外结束

倒带(磁带)

返回

输入文件中有1个'stop'错误'
2个输入文件意外结束'
结束子程序get_dim

我完全不知道为什么会出现这种行为。如果有人能帮我解决这个噩梦,我会很感激。如果子程序read_step的定义在一个模块中,那么你已经忘记添加USE语句模块到主程序的顶部,或模块中的相关过程不是PUBLIC。

使用该编译器(和其他一些)模块过程的链接器名称通常包含模块名称后面跟着' mp '(大小写可能有所不同),后面跟着过程名称,其中带有不同数量的前后下划线。您的链接器错误没有任何mangling,这表明在编译具有过程引用的范围时,编译器不认为该过程是模块过程。


I am trying to compile a fortran program which uses a bunch of modules. I obtain an error when I compile it, and it's driving me crazy. The error is originated by the addition of one subroutine and takes place when I try to recompile the program:

Main program contains these two lines:

--

call read_step(nStepOne,molOne)
call read_step(nStep,mol)

--

This is calling one of the subroutines in a file "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

--

When I try to compile it, the following error arises:

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

Other calls to subroutines in the same module did not give any error, and I just don't see any difference between the calls to the "old subroutines" and the one I just created.

An example of one of these "old subroutines", which does not give any complaint, is:

In the main program:

call get_dim(n_atom,nSnap,mol)

In the 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

I have absolutely no idea why this behavior. I'd be grateful if anybody could help me solve this nightmare. Thanks!

解决方案

If the definition of subroutine read_step is in a module, then you have either forgotten to add the USE statement for that module to the top of the main program, or the relevant procedures in the module are not PUBLIC.

With that compiler (and some others) linker names for module procedures generally consist of the module name followed by 'mp' (case may vary) followed by the procedure name, with various amounts of leading and trailing underscores salted to taste. Your linker error doesn't have any of that "mangling", which indicates that when compiling the scope with the procedure reference, the compiler doesn't think the procedure is a module procedure.

这篇关于Fortran编译错误 - 未定义的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆