具有许多模块的静态库 [英] static lib with many modules

查看:83
本文介绍了具有许多模块的静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用fortran开发静态库的情况下:

In case of developing a static lib using fortran:

lib由多个模块组成,例如模块a",模块b"等.

The lib is consist of multiple modules, e.g. "module a", "module b" etc..

每个模块都有公共变量,类型和过程.

Each of the modules has public variables, types and procedures.

现在,要在程序"test"中使用该库.

Now, want to use the lib in program "test".

一种可能的方法是使用每个模块,并在链接期间提供* .a lib文件.例如:

One possible method is to use each of the modules, and providing the *.a lib file during linking. e.g.:

program test
  use a
  use b
  ...
end program

但是如果只需要使用/包含一个模块/*.h会更好.例如:

But it would be better if only one module/*.h needs to be used/included. e.g.:

program test
  use all
  ...
end program

一种可能的解决方案是将过程的所有公共变量,类型和接口复制到模块全部"中,并使用模块全部"而不是单个模块.

One possible solution is to copy all public variables, types and interface of procedures into "module all", and use "module all" instead of the individual modules.

但是,如果修改了单个模块中的任何一个,则还需要修改所有模块"以适应更改.

But if any of the individual module is modified, "module all" also needs to be modified to meet the change.

是否有更合适的方法来解决,还是有自动工具来生成全部模块"?

Is there a more appropriate method to work around, or is there an automatic tool to generate the "module all"?

非常感谢您的投入.

推荐答案

我不会将代码从各个模块复制到模块"all",因为正如您所说,更改代码会导致额外的工作.和错误的可能性.而是在模块全部"中使用"那些模块.然后,当您希望全部使用它们时,就可以全部使用模块".当您需要一个特定的模块时,请使用该模块.禁止使用的是循环模块引用,因为它是禁止的:A用途B用途C用途A不允许.

I wouldn't copy code from the individual modules into module "all", because, as you say, that leads to extra work when code is changed. And possibility of error. Instead, "use" those modules in module "all". Then when you want them all you "use module all". When you want a particular module you use that one. What you have to guard against because it is forbidden is circular module references: A uses B uses C uses A is not allowed.

这篇关于具有许多模块的静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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