From 465578029f6ffe7ee3892ccc69de5e39d15b266d Mon Sep 17 00:00:00 2001 From: Matej Kenda Date: Tue, 17 Sep 2019 09:51:33 +0200 Subject: [PATCH] Python: More robust loading of IIO library that works on different platforms. Signed-off-by: Emmanuel Blot Tested-by: Matej Kenda --- bindings/python/iio.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bindings/python/iio.py b/bindings/python/iio.py index 3ffe2a290..88acb4fc1 100644 --- a/bindings/python/iio.py +++ b/bindings/python/iio.py @@ -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 @@ -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