Python runtime_library_dirs doesn't work on Mac

混江龙づ霸主 提交于 2019-11-30 05:42:49

I finally figured this out. The solution has two parts. First, setup.py needs to use extra_link_args to tell the linker to add a correct rpath to the compiled module:

if platform.system() == 'Darwin':
    extra_link_args.append('-Wl,-rpath,'+lib_path)

where lib_path is the directory where the libraries are installed. Second, all of the libraries you're linking against must have install names that begin with "@rpath/". For example, if a library is called "libFoo.dylib", its install name should be "@rpath/libFoo.dylib". You can use "install_name_tool -id" to change the install name of a library.

You can tell what libraries an extension links against with

otool -L pyext.so

I had a problem where an extension was linking to the wrong version of a library on my system. In that case I used install_name_tool to change the path to the library directly. For example,

install_name_tool -change /wrong/libfoo.dylib /right/libfoo.dylib pyext.so
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!