我想从Python中的Fortran共享库中调用一些函数.我在网上找到了一些链接并阅读它们,根据我的发现,我应该这样做
libadd = cdll.LoadLibrary('./libbin.so')
Run Code Online (Sandbox Code Playgroud)
加载共享对象.但是,此共享对象包含来自另一个共享库的一些符号.我阅读了cdll的帮助,但似乎无法同时加载多个共享对象文件.我怎样才能调用这个Fortran库中的函数,这个库很可能是由英特尔Fortran编译器编译的?
我正在研究一些fortran-calling-C代码,并且不清楚iso_c_binding模块的使用.
我有fortran和C接口在没有 iso_c_binding的情况下成功运行,问题是我是否仍应显式绑定函数和变量.例如,这有效:
program testprog
...
interface
subroutine c_parser(param)
integer, intent(in) :: param
end subroutine
end interface
integer :: a
call c_parser(a)
..
end program
/****************/
void c_parser_ (int* param)
Run Code Online (Sandbox Code Playgroud)
因此,在C函数中附加下划线,为其编写接口,并从fortran程序中调用它.我不使用指针或allocatables,我的所有代码都有int,char,float和逻辑,需要从fortran子程序移动到C.
iso_c_binding服务的确切目的是什么?有没有陷阱?作为一个例子,这提到了在通过绑定使用字符串时的一个警告(参见"不幸的是,至少在GNU和英特尔编译器上,声明"部分).
I am looking to use ctypes to call some old fortran libraries which were written by my boss a few years ago. I followed the example given in this previous question, and I get the results as expected.
However, when I modify the code, to get slightly closer to the situation I face, so that
integer function addtwo(a, b)
integer, intent(in) :: a, b
addtwo = a + b
end function
Run Code Online (Sandbox Code Playgroud)
becomes
real function addtwo(a, b)
integer, intent(in) :: …Run Code Online (Sandbox Code Playgroud)