如何从主应用程序解析库的编译器特定运行时初始化函数

发布于 2024-09-08 18:15:58 字数 405 浏览 1 评论 0原文

在创建库语言需要运行时初始化的混合语言库时,最佳实践是什么?

我有一个问题,我想在 Fortran 中创建一个要在 C++ 中使用的库。如果可能的话,我希望保持平台独立性和编译器独立性。现在,我使用过的两个编译器 G95 和 GFortran 都要求主应用程序调用某些特定于编译器的初始化例程,以便在使用库之前正确设置运行时。这些函数具有不同的名称和签名,具体取决于编译器(对于 G95,函数为 void g95_runtime_start(int argc, char *argv[]) )

我使用 CMake 来管理项目,库子项目是静态库。 我是否必须在主应用程序的 cmake 文件中找出用于库子项目的 fortran 编译器,然后让 CMake 在主项目中创建一个定义,以便我可以使用任一 init 例程有条件地编译主应用程序?感觉很别扭。有更好的办法吗?

What is the best practice when doing a mixed language library where the library language requires a runtime initialization?

I have a problem where I'd like to create a certain library in Fortran which is to used from C++. I'd want to preserve platform independence and compiler independence if possible. Now, the two compilers I have played with, G95 and GFortran both require that the main application calls certain compiler-specific initialization routines to properly set up the runtime before using the library. These functions have different names and signatures depending on the compiler (for G95 the function is void g95_runtime_start(int argc, char *argv[]) )

I'm using CMake to manage the project and the library subproject is a static library.
Do I somehow in my cmake file for the main application have to dig out which fortran compiler is used for the library subproject and then let CMake create a define in the main project so that I can conditionally compile the main app with either init routine? It feels very awkward. Is there a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

穿透光 2024-09-15 18:15:59

支持名称修改和备用电源 (AC_FC_MAIN)自动配置。我知道 cmake 小组对此进行了一些讨论另外,它可能在 FortranCinterface 模块中可用。但是我找不到任何相关文档。我更喜欢使用 autotools 而不是 cmake,因为这些类型的问题已经得到解决并有详细记录。

There is support for the name mangling and alternative mains (AC_FC_MAIN) in autoconf. I know there were some discussions on this in the cmake group also, so it might be available in the FortranCinterface module. However I could not find any docs on that. I prefer to work with autotools over cmake because these type of issues are already solved and well documented.

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