Hi,

i have the issue, that the example wont work, because there ist no "libknot.so"
on my system:

root@f-dns4:~# ldconfig -v 2>/dev/null | grep libknot
        libknot.so.8 -> libknot.so.8.0.0


root@f-dns4:~# lsb_release -a; dpkg-query -W knot
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:        18.04
Codename:       bionic

root@f-dns4:~# dpkg-query -W knot
knot    2.7.3-1~ubuntu18.04.1ppa2


I has made a patch for that, with a search order, if no path is given.
Hopefully this help to solve this issue.

Greetings
Frank
-- 
Frank Matthieß                 Stapenhorster Straße 42b, DE 33615 Bielefeld
                                           Mail: [email protected]
                  GnuPG: 9F81 BD57 C898 6059 86AA  0E9B 6B23 DE93 01BB 63D1
diff --git a/python/libknot/control.py b/python/libknot/control.py
index 433ad3598..cf527a956 100755
--- a/python/libknot/control.py
+++ b/python/libknot/control.py
@@ -27,7 +27,7 @@ Example:
         ctl.close()
 """
 
-from ctypes import cdll, c_void_p, c_int, c_char_p, c_uint, byref
+from ctypes import CDLL, cdll, c_void_p, c_int, c_char_p, c_uint, byref
 from enum import IntEnum
 import sys
 
@@ -44,9 +44,28 @@ CTL_ERROR = None
 def load_lib(path=None):
     """Loads the libknot library."""
 
+    LIB = None
+
     if path is None:
-        path = "libknot.dylib" if sys.platform == "darwin" else "libknot.so"
-    LIB = cdll.LoadLibrary(path)
+        if sys.platform == "darwin":
+            libnames = ["libknot.dylib"]
+        else:
+            libnames = ["libknot.so", "libknot.so.8" ]
+    else:
+        libnames = [ path ]
+
+    for libname in libnames:
+        try:
+            LIB = cdll.LoadLibrary(libname)
+        except OSError:
+            pass
+
+        if type(LIB) is CDLL:
+            break
+
+    if type(LIB) is not CDLL:
+        libs = " ".join(libnames)
+        raise Exception("Could not load shared library: {}".format(libs))
 
     global CTL_ALLOC
     CTL_ALLOC = LIB.knot_ctl_alloc
-- 
https://lists.nic.cz/cgi-bin/mailman/listinfo/knot-dns-users

Reply via email to