在Fortran90中调用同一模块中的函数
我是 Fortran90 的新手,我还没有找到我遇到的问题的答案。 我有一个用 Fortran 编写的模块,模块内有一些函数。
精简版本:
module vdiStringFunctions接口 vdiString 模块过程 vdiString1Char 最终接口
包含 字符 (128) 函数 vdiString1Char(CSTRING, sVar1) 字符(*)、意图(in)::CSTRING、sVar1 字符(128) :: vdiStringGeneral 字符(len = 128),维度(0:9) :: stringArray
stringArray(0) = adjustl(sVar1) vdiString1Char= vdiStringGeneral(CSTRING, stringArray) end function vdiString1Char character (128) function vdiStringGeneral(CSTRING, varArray) character(*), intent(in) :: CSTRING character(len=128), dimension(0:9), intent(in) :: varArray vdiStringGeneral = 'bla' end function vdiStringGeneral
结束模块vdiStringFunctions
当我尝试使用 Intel Visual Fortran XE 2011 进行编译时,出现以下错误:
错误 LNK2019:函数 _VDISTRINGFUNCTIONS_mp_VDISTRING1CHAR vdiStringFunctions.obj 中引用了无法解析的外部符号 _VDISTRINGGENERAL
因为函数 vdiStringGeneral 与调用 vdiString1Char 位于同一模块中,所以我没有遇到问题。 当我将 vdiStringGeneral 移到模块之外时,它可以正常编译。
因为它应该在 DLL 中使用,所以所有函数都应该位于模块内部。 我怎样才能让它以这种方式工作?
I am new to Fortran90 and I haven't found an answer to a problem I have.
I have a module written in Fortran with the some functions inside a module.
Stripped down version:
module vdiStringFunctionsinterface vdiString module procedure vdiString1Char end interface
contains character (128) function vdiString1Char(CSTRING, sVar1) character(*), intent(in) :: CSTRING, sVar1 character(128) :: vdiStringGeneral character(len=128), dimension(0:9) :: stringArray
stringArray(0) = adjustl(sVar1) vdiString1Char= vdiStringGeneral(CSTRING, stringArray) end function vdiString1Char character (128) function vdiStringGeneral(CSTRING, varArray) character(*), intent(in) :: CSTRING character(len=128), dimension(0:9), intent(in) :: varArray vdiStringGeneral = 'bla' end function vdiStringGeneral
end module vdiStringFunctions
When I try to compile with Intel Visual Fortran XE 2011 I get the following error:
error LNK2019: unresolved external symbol _VDISTRINGGENERAL referenced in function _VDISTRINGFUNCTIONS_mp_VDISTRING1CHAR vdiStringFunctions.obj
Because the function vdiStringGeneral is in the same module than the calling vdiString1Char I do not get the problem.
When I move the vdiStringGeneral outside of the module it compiles without problems.
Because it should be used in a DLL all functions should be inside the module.
How can I get it to work that way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除函数
vdiString1Char
中的vdiStringGeneral
声明。vdiStringGeneral
的接口已经是显式的,因为它是在同一模块中定义的。根据现在的声明,链接器正在寻找外部函数。
Remove the declaration of
vdiStringGeneral
in functionvdiString1Char
.The interface for
vdiStringGeneral
is already explicit, because it is defined in the same module.With the declaration you have now, the linker is looking for an external function.