在Fortran90中调用同一模块中的函数

发布于 2024-12-03 08:44:09 字数 1100 浏览 5 评论 0原文

我是 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 vdiStringFunctions

interface 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_畞蕅 2024-12-10 08:44:09

删除函数 vdiString1Char 中的 vdiStringGeneral 声明。
vdiStringGeneral 的接口已经是显式的,因为它是在同一模块中定义的。
根据现在的声明,链接器正在寻找外部函数。

Remove the declaration of vdiStringGeneral in function vdiString1Char.
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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文