致电 C/C++来自 Fortran 77 代码的代码
我正在尝试为 C++ 代码制作 Fortran 77 包装器。我还没有找到相关信息。 这个想法是使用 Fortran 77 程序中用 C++ 编写的库中的函数。
有谁知道该怎么做? 谢谢!
I'm trying to make a Fortran 77 wrapper for C++ code. I have not found information about it.
The idea is to use from functions from a lib that is written in C++ in a Fortran 77 progran.
Does anyone know how to do it?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
劳伦斯利弗莫尔国家实验室开发了一种名为 Babel 的工具,用于集成软件用多种语言编写成一个单一的、有凝聚力的应用程序。如果您的需求很简单,您可能只需将 C 包装器放在 C++ 代码上并从 Fortran 中调用它即可。但是,如果您的需求更高级,则可能值得提供 Babel< /a> 一看。
Lawrence Livermore National Laboratory developed a tool called Babel for integrating software written in multiple languages into a single, cohesive application. If your needs are simple you can probably just put C wrapper on your C++ code and call that from Fortran. However, if your needs are more advanced, it might be worth giving Babel a look.
从 C 调用 Fortran 很容易,从 Fortran 调用 C 可能很棘手,从 Fortran 调用 C++ 可能会变得……具有挑战性。
我在其他地方有一些注释< /a>.这些已经很古老了,但是在这种领域没有什么变化很快,所以那里可能仍然有一些有用的指针。
不幸的是,没有真正标准的方法来执行此操作,并且不同的编译器可能会以稍微不同的方式执行此操作。话虽如此,只有在传递字符串时您才可能遇到严重的麻烦。上面的资源指向一个名为 CNF 旨在在这里提供帮助,主要是通过提供 C 宏来糖化簿记。
然而,简短的版本是这样的:
foo
转换为_foo
或foo_
或其他一些变体(请参阅编译器文档)。这是您需要了解的大部分内容。剩下的就是烦人的细节,以及与编译器和链接器文档交朋友。您最终会比您想要的更多地了解链接器。
Calling Fortran from C is easy, C from Fortran potentially tricky, C++ from Fortran may potentially become ... challenging.
I have some notes elsewhere. Those are quite old, but nothing changes very rapidly in this sort of area, so there may still be some useful pointers there.
Unfortunately, there's no really standard way of doing this, and different compilers may do it slightly different ways. Having said that, it's only when passing strings that you're likely to run into major headaches. The resource above points to a library called CNF which aims to help here, mostly by providing C macros to sugar the bookkeeping.
The short version, however is this:
foo
into_foo
orfoo_
or some other variant (see the compiler docs).That's the majority of what you need to know. The rest is annoying detail, and making friends with your compiler and linker docs. You'll end up knowing more about linkers than you probably wanted to.