Skip to content

Commit

Permalink
Python: More robust loading of IIO library that works on different pl…
Browse files Browse the repository at this point in the history
…atforms.

Signed-off-by: Emmanuel Blot <[email protected]>
Tested-by: Matej Kenda <[email protected]>
  • Loading branch information
matejk committed Sep 26, 2019
1 parent c0012d0 commit 4655780
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bindings/python/iio.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ctypes import Structure, c_char_p, c_uint, c_int, c_size_t, \
c_ssize_t, c_char, c_void_p, c_bool, create_string_buffer, \
POINTER as _POINTER, CDLL as _cdll, memmove as _memmove, byref as _byref
from ctypes.util import find_library
from os import strerror as _strerror
from platform import system as _system
import weakref
Expand Down Expand Up @@ -58,8 +59,14 @@ class _Buffer(Structure):
_ChannelPtr = _POINTER(_Channel)
_BufferPtr = _POINTER(_Buffer)

_lib = _cdll('libiio.dll' if 'Windows' in _system() else 'libiio.so.0',
use_errno = True, use_last_error = True)
if 'Windows' in _system():
_iiolib = 'libiio.dll'
elif 'Darwin' in _system():
_iiolib = 'iio'
else:
_iiolib = 'libiio.so.0'

_lib = _cdll(find_library(_iiolib), use_errno = True, use_last_error = True)

_get_backends_count = _lib.iio_get_backends_count
_get_backends_count.restype = c_uint
Expand Down

0 comments on commit 4655780

Please sign in to comment.