From e58eabc5d3c6652f25a937954373186c9cb11d6e Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 4 Apr 2025 14:38:07 -0700 Subject: [PATCH] Use dlerror() when dlopen() fails. --- PythonKit/PythonLibrary.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/PythonKit/PythonLibrary.swift b/PythonKit/PythonLibrary.swift index 6149478..ab94a3f 100644 --- a/PythonKit/PythonLibrary.swift +++ b/PythonKit/PythonLibrary.swift @@ -205,6 +205,13 @@ extension PythonLibrary { // Must be RTLD_GLOBAL because subsequent .so files from the imported python // modules may depend on this .so file. let pythonLibraryHandle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL) + if pythonLibraryHandle == nil { + self.log("Failed to load library at '\(path)'.") + if let errorCString = dlerror() { + let errorString = String(cString: errorCString) + self.log("Reason for failure: \(errorString)") + } + } #endif if pythonLibraryHandle != nil {