Skip to contentSkip to conversation

package/libiio: fix python bindings without glibc utils

PATCH Applied Marcus Hoffmann via buildroot 1 participant 7 messages Dec 22, 2025 – Jan 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 package/libiio: fix python bindings without glibc utils

Libiio python bindings use ctypes and specifically the find_library() function from there to load the libiio.so shared library. This is not working unless glibc utils (specifically ldconfig) is installed to the target (alternatively the target would need gcc or binutils, for objdump or ld).

The easy fix here is to just bypass the find_library() machinery altogether as it's not needed on a buildroot system.

---
 ...-bindings-python-fix-library-loading.patch | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 package/libiio/0001-bindings-python-fix-library-loading.patch
package/libiio/0001-bindings-python-fix-library-loading.patch new file +41 -0
new file mode 100644
index 0000000000..f8715b4c5b
@@ -0,0 +1,41 @@
+From 4d4d17e2810f793b9f7fd8acad2a3c551dbff2b5 Mon Sep 17 00:00:00 2001
+From: Marcus Hoffmann <[email protected]>
+Date: Fri, 31 Mar 2023 20:13:07 +0200
+Subject: [PATCH] bindings: python: fix library loading
+
+On Linux the find_library() function requires ld, gcc, objdump
+or ldconfig on the target, which might not be present on a
+buildroot system. [1]
+We do not actually need this function at all, as we know the iio library
+will be referencable in the system under the name "libiio.so".
+So instead of kicking of this complicated cross-platform/cross-distro
+compatible machinery, we just pass in the name of the library we already
+know.
+
+[1] https://docs.python.org/3/library/ctypes.html#finding-shared-libraries
+
+Upstream: N/A, buildroot doesn't have to care about different OS's and
+distro setups, so we can just hardcode the lib name, but we cannot
+submit that upstream.
+
+Signed-off-by: Marcus Hoffmann <[email protected]>
+---
+ bindings/python/iio.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/bindings/python/iio.py b/bindings/python/iio.py
+index b91260cc..bde17694 100644
+--- a/bindings/python/iio.py
++++ b/bindings/python/iio.py
+@@ -224,7 +224,7 @@ else:
+     # Non-windows, possibly Posix system
+     _iiolib = "iio"
+ 
+-_lib = _cdll(find_library(_iiolib), use_errno=True, use_last_error=True)
++_lib = _cdll("libiio.so", use_errno=True, use_last_error=True)
+ 
+ _get_backends_count = _lib.iio_get_backends_count
+ _get_backends_count.restype = c_uint
+-- 
+2.25.1
+
Signature · 6 lines
2.52.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH 2/2 support/testing: add libiio python bindings runtime test

---
 .../tests/package/sample_libiio_bindings_python.py  |  3 +++
 .../tests/package/test_libiio_bindings_python.py    | 13 +++++++++++++
 2 files changed, 16 insertions(+)
 create mode 100644 support/testing/tests/package/sample_libiio_bindings_python.py
 create mode 100644 support/testing/tests/package/test_libiio_bindings_python.py
support/testing/tests/package/sample_libiio_bindings_python.py new file +3 -0
new file mode 100644
index 0000000000..74452192c2
@@ -0,0 +1,3 @@
+import iio
+
+assert len(iio.scan_contexts()) == 1
support/testing/tests/package/test_libiio_bindings_python.py new file +13 -0
new file mode 100644
index 0000000000..e8cf5c3d13
@@ -0,0 +1,13 @@
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestLibiioBindingsPython(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_LIBIIO=y
+        BR2_PACKAGE_LIBIIO_BINDINGS_PYTHON=y
+        """
+    sample_scripts = ["tests/package/sample_libiio_bindings_python.py"]
+    timeout = 10
Signature · 6 lines
2.52.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

Re: [Buildroot] [PATCH 2/2] support/testing: add libiio python bindings runtime test

In reply of:

Quoted 1 line

Applied to 2025.02.x and 2025.11.x. Thanks

Quoted 42 lines
---
 .../tests/package/sample_libiio_bindings_python.py  |  3 +++
 .../tests/package/test_libiio_bindings_python.py    | 13 +++++++++++++
 2 files changed, 16 insertions(+)
 create mode 100644 support/testing/tests/package/sample_libiio_bindings_python.py
 create mode 100644 support/testing/tests/package/test_libiio_bindings_python.py
support/testing/tests/package/sample_libiio_bindings_python.py new file +3 -0
new file mode 100644
index 0000000000..74452192c2
@@ -0,0 +1,3 @@
+import iio
+
+assert len(iio.scan_contexts()) == 1
support/testing/tests/package/test_libiio_bindings_python.py new file +13 -0
new file mode 100644
index 0000000000..e8cf5c3d13
@@ -0,0 +1,13 @@
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestLibiioBindingsPython(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_LIBIIO=y
+        BR2_PACKAGE_LIBIIO_BINDINGS_PYTHON=y
+        """
+    sample_scripts = ["tests/package/sample_libiio_bindings_python.py"]
+    timeout = 10
Signature · 6 lines
2.52.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

author Tested-by Fiona Klute on v1 1/2
#3 lore raw
In reply to Marcus Hoffmann via buildroot

Am 22.12.25 um 18:26 schrieb Marcus Hoffmann via buildroot:

Quoted 10 lines

Libiio python bindings use ctypes and specifically the find_library() function from there to load the libiio.so shared library. This is not working unless glibc utils (specifically ldconfig) is installed to the target (alternatively the target would need gcc or binutils, for objdump or ld).

The easy fix here is to just bypass the find_library() machinery altogether as it's not needed on a buildroot system.

The issue also affects musl, where ldconfig simply doesn't exist. It's clearly a bug in Python (where an open PR exists for years [1], and Alpine has been carrying a musl-specific patch for >10 years by now), but I think it's good to apply a workaround that's so simple.

Thank you,
Fiona

[1] https://github.com/python/cpython/pull/18380

Quoted 42 lines
---
  ...-bindings-python-fix-library-loading.patch | 41 +++++++++++++++++++
  1 file changed, 41 insertions(+)

create mode 100644 package/libiio/0001-bindings-python-fix-library-loading.patch

package/libiio/0001-bindings-python-fix-library-loading.patch new file +31 -0
new file mode 100644
index 0000000000..f8715b4c5b
@@ -0,0 +1,41 @@
+From 4d4d17e2810f793b9f7fd8acad2a3c551dbff2b5 Mon Sep 17 00:00:00 2001
+From: Marcus Hoffmann <[email protected]>
+Date: Fri, 31 Mar 2023 20:13:07 +0200
+Subject: [PATCH] bindings: python: fix library loading
+
+On Linux the find_library() function requires ld, gcc, objdump
+or ldconfig on the target, which might not be present on a
+buildroot system. [1]
+We do not actually need this function at all, as we know the iio library
+will be referencable in the system under the name "libiio.so".
+So instead of kicking of this complicated cross-platform/cross-distro
+compatible machinery, we just pass in the name of the library we already
+know.
+
+[1] https://docs.python.org/3/library/ctypes.html#finding-shared-libraries
+
+Upstream: N/A, buildroot doesn't have to care about different OS's and
+distro setups, so we can just hardcode the lib name, but we cannot
+submit that upstream.
+
+Signed-off-by: Marcus Hoffmann <[email protected]>
+---
+ bindings/python/iio.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/bindings/python/iio.py b/bindings/python/iio.py
+index b91260cc..bde17694 100644
+--- a/bindings/python/iio.py
++++ b/bindings/python/iio.py
+@@ -224,7 +224,7 @@ else:
+     # Non-windows, possibly Posix system

package/libiio/0001-bindings-python-fix-library-loading.patch line 41

Quoted 10 lines
package/libiio/0001-bindings-python-fix-library-loading.patch new file +10 -0
+     _iiolib = "iio"
+
+-_lib = _cdll(find_library(_iiolib), use_errno=True, use_last_error=True)
++_lib = _cdll("libiio.so", use_errno=True, use_last_error=True)
+
+ _get_backends_count = _lib.iio_get_backends_count
+ _get_backends_count.restype = c_uint
+--
+2.25.1
+

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#4 lore raw
In reply to Marcus Hoffmann via buildroot

Hello Marcus,

Quoted 6 lines · On Mon, 22 Dec 2025 18:26:36 +0100 Marcus Hoffmann via buildroot…

Libiio python bindings use ctypes and specifically the find_library() function from there to load the libiio.so shared library. This is not working unless glibc utils (specifically ldconfig) is installed to the target (alternatively the target would need gcc or binutils, for objdump or ld).

Quoted 8 lines

The easy fix here is to just bypass the find_library() machinery altogether as it's not needed on a buildroot system.

---
 ...-bindings-python-fix-library-loading.patch | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 package/libiio/0001-bindings-python-fix-library-loading.patch

Thanks, I have applied both patches. However I must admit that for PATCH 1/2, I would probably have preferred to backport the on-going PR on cpython, which fixes the problem for all cases, not just libiio.

Reading the discussion on the PR, I think it was improperly presented as being needed for "musl", and used only for musl. I would suggest to not present it as something musl-specific, but rather something that makes the lookup for the C/C++ libraries more portable (and therefore probably drop using ldconfig entirely). This would have addressed the concern raised on the PR that this is musl specific, and musl is not a supported platform, yadayadayada.

Thomas

Signature · 7 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#5 lore raw

Am 27.12.25 um 16:57 schrieb Thomas Petazzoni via buildroot:

Quoted 24 lines

Hello Marcus,

Quoted 6 lines · On Mon, 22 Dec 2025 18:26:36 +0100 Marcus Hoffmann via buildroot…

Libiio python bindings use ctypes and specifically the find_library() function from there to load the libiio.so shared library. This is not working unless glibc utils (specifically ldconfig) is installed to the target (alternatively the target would need gcc or binutils, for objdump or ld).

Quoted 8 lines

The easy fix here is to just bypass the find_library() machinery altogether as it's not needed on a buildroot system.

---
  ...-bindings-python-fix-library-loading.patch | 41 +++++++++++++++++++
  1 file changed, 41 insertions(+)

create mode 100644 package/libiio/0001-bindings-python-fix-library-loading.patch

Thanks, I have applied both patches. However I must admit that for PATCH 1/2, I would probably have preferred to backport the on-going PR on cpython, which fixes the problem for all cases, not just libiio.

Quoted 7 lines

Reading the discussion on the PR, I think it was improperly presented as being needed for "musl", and used only for musl. I would suggest to not present it as something musl-specific, but rather something that makes the lookup for the C/C++ libraries more portable (and therefore probably drop using ldconfig entirely). This would have addressed the concern raised on the PR that this is musl specific, and musl is not a supported platform, yadayadayada.

Unfortunately the CPython PR [1] as it is actually *is* musl specific, importing it would only help for musl-based systems (fine for my builds, but not a general solution). The current ctypes.util.find_library() implementation using glibc executables has issues beyond musl compatibility as Marcus' point about missing ldconfig shows, but that hasn't even been mentioned in the PR discussion.

Best regards,
Fiona

[1] https://github.com/python/cpython/pull/18380
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#6 lore raw
In reply to Marcus Hoffmann via buildroot

In reply of:

Quoted 10 lines

Libiio python bindings use ctypes and specifically the find_library() function from there to load the libiio.so shared library. This is not working unless glibc utils (specifically ldconfig) is installed to the target (alternatively the target would need gcc or binutils, for objdump or ld).

The easy fix here is to just bypass the find_library() machinery altogether as it's not needed on a buildroot system.

Applied to 2025.02.x and 2025.11.x. Thanks

Quoted 59 lines
---
 ...-bindings-python-fix-library-loading.patch | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 package/libiio/0001-bindings-python-fix-library-loading.patch
package/libiio/0001-bindings-python-fix-library-loading.patch new file +41 -0
new file mode 100644
index 0000000000..f8715b4c5b
@@ -0,0 +1,41 @@
+From 4d4d17e2810f793b9f7fd8acad2a3c551dbff2b5 Mon Sep 17 00:00:00 2001
+From: Marcus Hoffmann <[email protected]>
+Date: Fri, 31 Mar 2023 20:13:07 +0200
+Subject: [PATCH] bindings: python: fix library loading
+
+On Linux the find_library() function requires ld, gcc, objdump
+or ldconfig on the target, which might not be present on a
+buildroot system. [1]
+We do not actually need this function at all, as we know the iio library
+will be referencable in the system under the name "libiio.so".
+So instead of kicking of this complicated cross-platform/cross-distro
+compatible machinery, we just pass in the name of the library we already
+know.
+
+[1] https://docs.python.org/3/library/ctypes.html#finding-shared-libraries
+
+Upstream: N/A, buildroot doesn't have to care about different OS's and
+distro setups, so we can just hardcode the lib name, but we cannot
+submit that upstream.
+
+Signed-off-by: Marcus Hoffmann <[email protected]>
+---
+ bindings/python/iio.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/bindings/python/iio.py b/bindings/python/iio.py
+index b91260cc..bde17694 100644
+--- a/bindings/python/iio.py
++++ b/bindings/python/iio.py
+@@ -224,7 +224,7 @@ else:
+     # Non-windows, possibly Posix system
+     _iiolib = "iio"
+ 
+-_lib = _cdll(find_library(_iiolib), use_errno=True, use_last_error=True)
++_lib = _cdll("libiio.so", use_errno=True, use_last_error=True)
+ 
+ _get_backends_count = _lib.iio_get_backends_count
+ _get_backends_count.restype = c_uint
+-- 
+2.25.1
+
Signature · 6 lines
2.52.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot