Skip to content

Commit c24722c

Browse files
committed
fix_mac_issue
1 parent 18c90bc commit c24722c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

setup.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,15 @@ def build_shared_lib(self, lib_name, build_info):
401401

402402
if platform_system == 'Darwin':
403403
build_info['extra_link_args'].append(f"-Wl,-install_name,@loader_path/{lib_file}")
404-
self.compiler.linker_so = ['-dynamiclib' if val=='-bundle' else val for val in self.compiler.linker_so]
404+
# On macOS, building a shared library must use '-dynamiclib' instead of '-bundle'.
405+
# Depending on setuptools/distutils, linker_so can be a string or a list.
406+
linker_so = getattr(self.compiler, 'linker_so', None)
407+
if isinstance(linker_so, (list, tuple)):
408+
self.compiler.linker_so = [('-dynamiclib' if val == '-bundle' else val) for val in linker_so]
409+
elif isinstance(linker_so, str):
410+
# Replace all occurrences safely in the string variant
411+
self.compiler.linker_so = linker_so.replace('-bundle', '-dynamiclib')
412+
# If linker_so is None or unexpected type, do nothing; default behavior will apply
405413
self.compiler.link_shared_object(
406414
objects,
407415
lib_file,

0 commit comments

Comments
 (0)