如何将Fortran项目与C+&#x2B相结合项目?
我正在使用C ++进行数字项目,但它将在另一个Fortran项目中使用多个Fortran子例程。 Fortran项目具有头文件和多个子例程文件。文件依赖项如下图所示:
我想知道如何在Visual Studio中实现此界面?我可以设置两个项目,一个用于fortran,它包括所有fortran代码,另一个用于CPP,在标题文件和类文件中我使用extern“ c”关键词来声明Fortran Subroutine?
Update1:Fotran的编译器是Intel Fortran,C ++的编译器是使用MFC和标准Windows库的MSVC。
I am working on a numerical project with C++, but it will use several fortran subroutines in another fortran project. The fortran project has head files and multiple subroutine files. The file dependency is shown in the figure below:
I am wondering that how can I implement this interface in visual studio? Can I set up two projects, one is for fortran, it includes all fortran code, another is for Cpp, in the header file and class file I use extern "C" key word to declare the fortran subroutine?
Update1: The compiler for fotran is Intel Fortran, the compiler for C++ is msvc using MFC and the standard windows libraries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为C ++零件创建一个可执行的项目(和VS解决方案)。现在,添加到该解决方案一个fortran静态库项目,然后将您的fortran文件添加到其中。
右键单击C ++项目,然后选择“构建依赖关系”>项目依赖性。选中Fortran库项目的框,以使其成为C ++项目的依赖。在VS的较旧版本中,这是您需要将库链接到其中的全部,但是MS删除了该功能的非Microsoft编译器,因此您还有一些其他步骤:
这应该是您需要构建的全部。您可能需要在FORTRAN代码中使用C互操作性功能,包括将绑定(C)添加到C ++代码所调用的任何例程中,并使用name = specifier,具有case敏感的名称C ++将使用。请注意,仅当例程具有绑定(C)时,Fortran值属性意味着逐个价值。
Intel Fortran样品捆绑包中有一个有效的C_CALLS_FORTRAN示例, https://software.intel.com/content/www/us/en/develop/download/776976.html (在Compiler_f \ mixchlanguage下)。如果您需要更多帮助,请在Intel fortran用户论坛上询问 https://community.intel.com/t5/intel-fortran-compiler/bd-p/fortran-compiler
Create an executable project (and VS Solution) for the C++ part. Now add to that solution a Fortran Static Library project and add your Fortran files to it.
Right click on the C++ project and select Build Dependencies > Project Dependencies. Check the box of the Fortran library project to make it a dependent of the C++ project. In older versions of VS, this is all you would need to have the library linked in, but MS removed that function for non-Microsoft compilers, so you have some additional steps:
This should be all you need to build. You will likely want to use the C interoperability features in your Fortran code, including adding BIND(C) to any routines called by the C++ code, with a NAME= specifier with the case-sensitive name C++ will use. Be aware that the Fortran VALUE attribute means pass-by-value only when the routine has BIND(C).
There is a worked C_Calls_Fortran example in the Intel Fortran samples bundle at https://software.intel.com/content/www/us/en/develop/download/776976.html (under compiler_f\MixedLanguage). If you need more help, ask in the Intel Fortran user forum at https://community.intel.com/t5/Intel-Fortran-Compiler/bd-p/fortran-compiler