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

Nils Wagner nwagner at iam.uni-stuttgart.de
Mon Feb 22 08:57:14 EST 2010


On Mon, 22 Feb 2010 22:18:23 +0900
  David Cournapeau <cournape at gmail.com> wrote:
> On Mon, Feb 22, 2010 at 10:01 PM, Nils Wagner
> <nwagner at iam.uni-stuttgart.de> wrote:
> 
>>
>> ar x test.a
>> gfortran -shared *.o -o libtest.so -lg2c
>>
>> to build a shared library. The additional option -lg2c 
>>was
>> necessary due to an undefined symbol: s_cmp
> 
> You should avoid the -lg2c option at any cost if 
>compiling with
> gfortran. I am afraid that you got a library compiled 
>with g77. If
> that's the case, you should use g77 and not gfortran. 
>You cannot mix
> libraries built with one with libraries with another.
> 

g77 -shared *.o -o libtest.so -lg2c

failed with

/usr/lib/64/gcc-lib/x86_64-suse-linux/3.3.5/../../../../x86_64-suse-linux/bin/ld: 
cannot find -lgcc_s

IIRC that is a known bug related to SuSE .

Are you aware of a solution ?

Cheers,
                 Nils


>>
>> Now I am able to load the shared library
>>
>> from ctypes import *
>> my_lib = CDLL('test.so')
>>
>> What are the next steps to use the library functions
>> within python ?
> 
> You use it as you would use a C library:
> 
> http://python.net/crew/theller/ctypes/tutorial.html
> 
> But the fortran ABI, at least for code built with g77 
>and gfortran,
> pass everything by reference. To make sure to pass the 
>right
> arguments, I strongly suggest to double check with the 
>.h you
> received.
> 
> cheers,
> 
> David
  



More information about the NumPy-Discussion mailing list