[Numpy-discussion] Calling routines from a Fortran library using python

Nils Wagner nwagner@iam.uni-stuttgart...
Thu Feb 18 04:33:02 CST 2010


On Thu, 18 Feb 2010 19:21:03 +0900
  David Cournapeau <david@silveregg.co.jp> wrote:
> Nils Wagner wrote:
>> On Thu, 18 Feb 2010 18:32:18 +0900
>>   David Cournapeau <david@silveregg.co.jp> wrote:
>>> Nils Wagner wrote:
>>>> Hi all,
>>>>
>>>> I have a static  library (*.a) compiled by gfortran but 
>>>> no 
>>>> source files.
>>>> How can I call routines from that library using python ?
>>> Is there any kind of interface (.h, etc...) ? If this is 
>>> a proprietary 
>>> library, there has to be something so that it can be 
>>> called from C, and 
>>> anything that can be called from C can be called from 
>>> python. If you 
>>> don't know at least the functions signatures, it will be 
>>> very difficult 
>>> (you would have to disassemble the code to find how the 
>>> functions are 
>>> called, etc...).
>>>
>>> cheers,
>>>
>>> David
>>   
>> Hi David,
>> 
>> you are right. It's a proprietary library.
>> I found a header file (*.h) including prototype 
>> declarations of externally callable procedures.
>> 
>> How can I proceed ?
> 
> Exactly as you would do for a C library (ctypes, cython, 
>by hand, swig, 
> etc...). Once you have the header (plus the C->Fortran 
>ABI convention, 
> which depend on your compilers and platforms), it is 
>exactly as calling 
> a C function in a C library,
> 
> cheers,
> 
> David
  
To be honest that's over my head. I mean I have never used 
C before.
Where can I find a step-by-step example for my task ?

Nils


More information about the NumPy-Discussion mailing list