[Numpy-discussion] ctypes: how does load_library work ?
David Cournapeau
david at ar.media.kyoto-u.ac.jp
Fri Aug 18 06:36:21 CDT 2006
Stefan van der Walt wrote:
> On Fri, Aug 18, 2006 at 01:54:44PM +0900, David Cournapeau wrote:
>
>> import numpy as N
>> from ctypes import cdll, POINTER, c_int, c_uint
>>
>> _hello = cdll.LoadLibrary('libhello.so')
>>
>> _hello.sum.restype = c_int
>> _hello.sum.artype = [POINTER(c_int), c_uint]
>>
>> def sum(data):
>> return _hello.sum(data.ctypes.data_as(POINTER(c_int)), len(data))
>>
>> n = 10
>> data = N.arange(n)
>>
>> print data
>> print "sum(data) is " + str(sum(data))
>>
>>
>> That works OK, but to avoid the platform dependency, I would like to use
>> load_library from numpy: I just replace the cdll.LoadLibrary by :
>>
>> _hello = N.ctypeslib.load_library('hello', '.')
>>
>
> Shouldn't that be 'libhello'? Try
>
> _hello = N.ctypes_load_library('libhello','__file__')
>
Well, the library name convention under unix, as far as I know, is
'lib'+ name + '.so' + 'version'. And if I put lib in front of hello, it
then does not work under windows.
David
More information about the Numpy-discussion
mailing list