Skip to content

Commit

Permalink
OSX: load shared libraries using RTLD_GLOBAL
Browse files Browse the repository at this point in the history
- Sometimes this isn't needed, but to be safe just do it always
  • Loading branch information
virtuald committed Dec 17, 2023
1 parent 46c5d1e commit ccce032
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions robotpy_build/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit ccce032

Please sign in to comment.