在我的 Fortran 程序中调用 SuperLU 库
我试图让这个 superLU 稀疏矩阵求解器运行,但我似乎无法编译它。我正在用 Fortran 编写程序,因此我尝试从我的程序中调用 superLU。我正在使用 fortran 的 g95 编译器。
http://crd.lbl.gov/~xiaoye/SuperLU/#superlu
我如何在 Fortran 中编译它?我尝试了一下,它显示错误无法执行'cc1'
,未找到文件。我不在乎我使用什么 Fortran 编译器,只要我能从 Fortran 调用这个 superLU 就行。
我不太了解如何将 Fortran 与 C++ 程序链接,我所做的是 g95 -o test f77_main.f hbcode1.f c_fortran_dgssv.c
I'm trying to get this superLU sparse matrix solver to run, but I can't seem to compile it. I'm writing my program with Fortran, and so I'm trying to call superLU from my program. I'm using g95 compiler for fortran.
http://crd.lbl.gov/~xiaoye/SuperLU/#superlu
How can I compile this in Fortran? I tried and it said error cannot exec 'cc1'
, no file found. I don't care what Fortran compiler I use, just any way I can call this superLU from Fortran.
I don't know much about linking Fortran with C++ programs, what I did is g95 -o test f77_main.f hbcode1.f c_fortran_dgssv.c
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用 Fortran ISO C 绑定从 Fortran 调用 C 例程,反之亦然。此绑定是 Fortran 2003 的一部分,但已广泛使用了数年,它通知 Fortran 使用 C 调用约定。它是语言的一部分,因此独立于编译器和平台。除了这里之前的答案之外,gfortran 手册中的“混合语言编程”下还有代码示例。还有许多 Fortran 接口的示例,用于调用 GNU 科学库的 C 例程,网址为 http://www.lrz.de/services/software/mathematik/gsl/fortran/index.html。
重新如何编译&链接混合的 Fortran 和C 程序...通常更容易使用 Fortran 编译器进行链接步骤,因为它引入了额外的 Fortran 运行时库。因此,分两步进行:将 C 例程编译为目标文件,然后在下一步中编译 Fortran 例程并链接 Fortran 例程和预编译的 C 例程。如果使用 C++,请使用“extern C”使其与 C 兼容。因此,例如:
gcc -c MyCRoutine.c
gfortran FortranMain.f95 MyCRoutine.o
I recommend the use of the Fortran ISO C Binding for calling C routines from Fortran, or vice-a-versa. This binding, which is part of Fortran 2003 but widely available for several years, informs Fortran to use C calling conventions. It is part of the language and so compiler and platform independent. Besides previous answers here, there are code examples in the gfortran manual under "Mixed-Language Programming". There are also many examples of Fortran interfaces to call the C routines of the GNU Scientific Library at http://www.lrz.de/services/software/mathematik/gsl/fortran/index.html.
Re how to compile & link a mixed Fortran & C program ... generally is easier to use the Fortran compiler for the linking step because it brings in extra Fortran runtime libraries. So proceed in two steps: compile your C routines to object files, then in the next step compile the Fortran routines and link the Fortran routines and the pre-compiled C routines. If using C++, use "extern C" to make it compatible with C. So, for example:
gcc -c MyCRoutine.c
gfortran FortranMain.f95 MyCRoutine.o
解决问题的一个好的开始可以在此处< /a>.
您将 .c 文件传递给 g95 看起来有点奇怪。您应该使用 GCC 编译 C 文件,然后将生成的 .o 文件链接到编译的 Fortran 代码。
A good start to solving your problem can be found in a previous answer here.
It looks a bit strange that you are passing a .c file to g95. You should compile the C file using GCC, then link the resulting .o file to your compiled fortran code.