From ccce0324fff40fc88dd4df4e3c3ccdca86ad817b Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Sun, 17 Dec 2023 16:03:42 -0500 Subject: [PATCH] OSX: load shared libraries using RTLD_GLOBAL - Sometimes this isn't needed, but to be safe just do it always --- robotpy_build/wrapper.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/robotpy_build/wrapper.py b/robotpy_build/wrapper.py index 7ebce05..f7efb0e 100644 --- a/robotpy_build/wrapper.py +++ b/robotpy_build/wrapper.py @@ -488,13 +488,18 @@ def _write_libinit_py(self, libnames): init += "\n" if libnames: - init += "from ctypes import cdll\n\n" + if self.platform.os == "osx": + init += "from ctypes import CDLL, RTLD_GLOBAL\n\n" + else: + init += "from ctypes import cdll\n\n" for libname in libnames: init += "try:\n" - init += ( - f' _lib = cdll.LoadLibrary(join(_root, "lib", "{libname}"))\n' - ) + if self.platform.os == "osx": + init += f' _lib = CDLL(join(_root, "lib", "{libname}"), mode=RTLD_GLOBAL)\n' + else: + init += f' _lib = cdll.LoadLibrary(join(_root, "lib", "{libname}"))\n' + init += "except FileNotFoundError:\n" init += f' if not exists(join(_root, "lib", "{libname}")):\n' init += f' raise FileNotFoundError("{libname} was not found on your system. Is this package correctly installed?")\n'