使用模块文件分发编译的Fortran库 [英] Distribute compiled fortran library with module files

查看:128
本文介绍了使用模块文件分发编译的Fortran库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用大量模块的 Fortran 库。我在Windows上使用 ifort 编译器。因此,我得到了一个用于库的 *。lib 文件和用于所用模块的 *。mod 文件。

这个缺点是我也必须分发 *。mod 文件,如果我想要使用在另一个程序中编译库。这怎么能被阻止?我看到了两种可能性:


  1. 创建一个接口,其中定义了用于调用库模块内部函数或过程的函数。因此,我只需提供定义接口的文件。

  2. 使用c接口并导出所有应该从库之外使用的模块函数和过程的名称在函数定义中 bind(c)。然后,我可以使用一个类似c的头文件来分发这个库。

还有其他可能吗?什么是分发使用模块的Fortran编译库的最佳实践?

我认为要分发<$ c $到目前为止,c> .mod 文件是最简单的,如果它应该使用来自Fortran的调用。如果要从其他语言中调用它,则无论如何您都需要C接口。



坏的是丢失了Fortran显式接口。如果您提供包含接口块的包含文件,但只提供 .mod 文件更好,恕我直言,使用选项编号1您可能仍然拥有它。


I have a Fortran library that uses a lot of modules. I use the ifort compiler on Windows. Therefore, I get a *.lib file for the library and *.mod files for the used modules.

This has the disadvantage that I also have to distribute the *.mod files, if I want to use the compiled library in another programme. How can this be prevented? I see two possibilities:

  1. Create an interface, where functions are defined that are used to call the functions or procedures inside the library modules. So, I only have to provide the file, where the interface is defined.
  2. Use the c-interface and export names for all module functions and procedures that should be used from outside the library using bind(c) in function definitions. Then I can distribute the library with a c-like header file.

Are there any other possibilities? What are best practices to distribute a compiled fortran library that uses modules?

解决方案

I think that to distribute also the .mod file is the easiest, by far, if it supposed to by used called from Fortran. If it is to be called from other languages, you need the C interface anyway.

The bad thing is loosing the Fortran explicit interfaces. With option number 1 you can probably still have it, if you supply an include file with interface blocks, but just supplying the .mod file is better IMHO.

这篇关于使用模块文件分发编译的Fortran库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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