From de6e6e24ab60e255c747ebd8f34c0eebade5d513 Mon Sep 17 00:00:00 2001
From: "Uwe L. Korn" <uwe.korn@quantco.com>
Date: Fri, 29 Sep 2023 15:58:27 +0200
Subject: [PATCH 1/3] Link to dl library

---
 setup.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/setup.py b/setup.py
index f9cabaa..0c689b6 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,7 @@
 import sys, os, platform
 import subprocess
 import errno
+import sysconfig
 
 # the setuptools distutils shim should make distutils available, but this will definitely do
 # it, since setuptools is now required at build-time
@@ -113,6 +114,10 @@ def use_pkg_config():
     _ask_pkg_config(library_dirs,       '--libs-only-L', '-L', sysroot=True)
     _ask_pkg_config(extra_link_args,    '--libs-only-other')
     _ask_pkg_config(libraries,          '--libs-only-l', '-l')
+    # This is needed for linking to 'dlopen', 'dlclose', 'dlsym' and 'dlerror'
+    # from _cffi_backend.c for uClibc.
+    if '-ldl' in (sysconfig.get_config_var('LIBS') or '').split(' '):
+        libraries.append('dl')
 
 def use_homebrew_for_libffi():
     # We can build by setting:
-- 
2.39.3 (Apple Git-145)

