模块和传统Fortran 77代码 [英] Modules and legacy Fortran 77 codes

查看:365
本文介绍了模块和传统Fortran 77代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组blas / lapack函数,我从NETLIB网站。我想把这些功能放在一个Fortran模块。我的代码的其余部分在Fortran 90.所以我这样做:

 模块modname 
包含


双精度函数ddot(n,dx,incx,dy,incy)



end function


子程序dpofa(a,lda,n,info)


double precision ddot

结束子程序dopfa
结束模块



当我使用

  gfortran modname.f90 

我收到以下错误:


/tmp/ccC2EUFj.o:在函数 __ temp_MOD_dpofa':
temp.f90 :(。text + 0x11c):未定义的引用
ddot _'


我忽略了关于的未定义的引用的错误,我意识到它发生,因为我没有程序..结束程序语句的文件。



但是,如果我删除 module modname 包含 end module 编译器编译没有任何问题。



可能是什么问题?


<在你的非模块方法中,你有很多外部函数和子程序。也就是说,如果这些在模块外部定义,则一个过程不具有关于另一个的线索。通过使用声明语句 double precision ddot 可以告诉子程序 dpofa 关于函数 ddot / code>。编译器将该名称改为 ddot _ (有关详细信息,请参阅其他部分),还会将真实函数的名称改为相同。链接器在需要时将一个符号解析为另一个符号。



当你使用一个模块时,你仍然有这个外部函数声明,但现在真正的函数,在同一个模块中,不再是外部的。相反,有一个模块过程被损坏到例如 __ temp_MOD_ddot 。您不是使用损坏名称 ddot _ 创建一个函数。



您可能有引用在 dpofa 中的函数 ddot ,但在模块版本中将是符号 ddot_ 这是未定义的。



您将要删除现在在同一个模块中定义的那些函数的函数声明,不再外部。


I have set of blas/lapack functions that I got from NETLIB website. I would like to put these functions inside a Fortran module. The rest of my code is in Fortran 90. So I go about doing this:

module modname
contains


double precision function ddot(n,dx,incx,dy,incy)
.
.
.
end function 


subroutine dpofa(a,lda,n,info) 
.
.
        double precision ddot
.
end subroutine dopfa
end module

When I compile using

gfortran modname.f90

I get the following error:

/tmp/ccC2EUFj.o: In function __temp_MOD_dpofa': temp.f90:(.text+0x11c): undefined reference toddot_'

I am ignoring the error about Undefined reference to main, I realize it happens because I do not have program .. end program statements in the file.

If, however, I remove the lines with module modname, contains and end module the compiler compiles without any issues.

What could possibly be the issue?

解决方案

In your non-module approach you have lots of external functions and subroutines. That is, if these are defined outside the module then one procedure has no clue about another. You tell the subroutine dpofa about the function ddot by using the declaration statement double precision ddot. The compiler mangles that name to ddot_ (see elsewhere for details of that) and also mangles the name of the real function you have to the same. The linker resolves one symbol to the other when needed.

When you come to using a module, you still have this external function declaration, but now the real function you have, in the same module, is no longer external. Instead, there is a module procedure which gets mangled to something like __temp_MOD_ddot. You aren't creating a function with the mangled name ddot_ any longer.

You presumably have a reference to the function ddot in dpofa, but in the module version that will be to the symbol ddot_ which isn't defined.

You'll want to remove the function declarations for those functions which are now defined in the same module, and are no longer external.

这篇关于模块和传统Fortran 77代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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