在 Fortran 中使用外部模块
我尝试使用两个具有相同名称的外部 Fortran 模块(在本例中为 mod_param)。因此,当我尝试编译代码时,编译器给出以下错误,
mod_param.o: In function mod_param._': mod_param.f90:(.text+0x0): mod_param._' 的多重定义 mod_param.o:mod_param.F90:(.text+0x0): 首先在这里定义
有没有办法解决它而不重命名模块文件及其名称?我不喜欢重命名,因为外部模块是由其他人维护的,我不想使用它们。有什么特殊的用途声明可以做到这一点吗?
I try to use two external Fortran module which are in same name (in this case mod_param). So, when i try to compile my code, the compiler gives the following error,
mod_param.o: In function mod_param._':
mod_param._'
mod_param.f90:(.text+0x0): multiple definition of
mod_param.o:mod_param.F90:(.text+0x0): first defined here
is there any way to solve it without renaming the one of the module file and its name? I don't prefer the renaming because the external modules are maintained by someone else and i don't want to play with them. Is there any special use statement to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不需要。至少需要在其中一个模块中更改源代码中的函数名称。
由于代码是由其他人维护的,因此请考虑自动重命名:也许项目 Makefile 可以运行一个 sed 脚本来更改函数名称。为了使依赖关系清晰,请确保将 sed 脚本的输出设置为用于编译的新文件名 - 原始模块将具有未编译或链接到项目中的文件名。
即使可以以某种方式将它们链接到同一个名称,您将如何控制哪个名称被调用?
No. It is necessary to change the function name in the source code in at least one of the modules.
Since the code is being maintained by someone else, consider automating the renaming: perhaps the project Makefile can run a
sed
script which changes the function names. So that the dependencies are clear, be sure to make the output of the sed script a new file name which is used to be compiled—the virgin module would have a filename which is not compiled or linked into the project.Even if it were somehow possible to link them both in with the same name, how would you control which was called with the name?
根据 F2003 标准,模块名称是全局实体,并且在程序中必须是唯一的,但内部模块有一些例外。
所以,这将是一个不(此外,如果他们同名,你如何区分他们?)
According to F2003 standard module names are global entities and must be unique in a program, with some exteptions for intrinsic modules.
So, that would be a no (Besides, how would you tell them apart were they of the same name?)