链接 2 个具有相同模块名称和子例程名称的库
我在一个 Fortran 项目中,我必须链接 2 个具有相同模块名称的库,在它们下具有相同的子例程名称。 我正在使用 Intel Fortran 编译器,当我导入模块并调用子例程时,它总是转到第一个链接的模块。
有没有一种方法可以专门从特定库调用子例程?
这是一些伪代码:
Lib1 和 Lib 2 都有这个:
module foo
subroutine func()
write (*, *) "Hello from Lib1" ! or Lib2
end subroutine()
end module
Main
program Main
use foo, only: func
call func()
end program
CMakeLists.txt
target_link_libraries(Main PRIVATE libLib1.so libLib2.so)
I'm on a Fortran project, that I have to link 2 libraries who have same module name, under which, have same subroutine name.
I'm using Intel Fortran compiler, when I import the module and call the subroutine, it always goes to the first one linked.
Is there a way that I can specifically call a subroutine from a specific library?
Here's some pseudo code:
Lib1 and Lib 2 both have this:
module foo
subroutine func()
write (*, *) "Hello from Lib1" ! or Lib2
end subroutine()
end module
Main
program Main
use foo, only: func
call func()
end program
CMakeLists.txt
target_link_libraries(Main PRIVATE libLib1.so libLib2.so)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Fortran 中两个模块名称相同是非法的。在编写其他用户使用的库时,我强烈建议对模块名称和其他可能发生冲突的实体使用诸如
mylibrary_foo
之类的前缀。现在除了重命名这些东西之外你不能做太多事情。如果您想尝试使用工具链中的技巧以某种方式分离这些内容,您首先必须详细指定您的工具链,但我对此表示怀疑。
It is illegal to have two modules name identically in Fortran. When writing libraries used by other users, I highly recommend to use prefixes such as
mylibrary_foo
for module names and other entities that might clash.Now you cannot do much, apart from renaming the stuff. If you want to try to somehow separate the stuff using tricks in your toolchain, you firstly have to specify your toolchain in detail, but I'm sceptical.