I would like to call some functions from a Fortran shared library in Python. I have found some links on the net and read them, and according what I found, I should do
libadd = cdll.LoadLibrary('./libbin.so')
to load the shared object. However, this shared object includes some symbols from another shared library. I read the help of cdll however it does not seem possible to load several shared object files at the same time. How may I call functions from this Fortran library, which is most probably compiled by the Intel Fortran compiler?
You’ll need to know the signatures of the functions in the shared object. Do you have the source code, or some reference which explains the function names and argument types?
For example, I have this source code (mult.f90):
.. and to demonstrate how you can load and use multiple shared objects at once, I also have (add.f90):
Compile, examine symbols:
Notice the symbol name in the shared object has an underscore appended. Since I have the source, I know that the signature is
multiply_(int *a, int *b), so it is easy to invoke that function fromctypes:Output: