新版 MacOS 无法从 /usr/local/lib 加载动态链接库的办理办法

[复制链接]
发表于 2025-11-9 02:45:23 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本身编写的动态链接库在Unix规范下一样平常位于/usr/local/lib,在2023年及之前的MacOS版本中,直接将动态库安装到该位置即可在步调运行时加载,但是升级MacOS版本后,ld就报错。
错误征象

运行步调,报错
  1. dyld[6376]: Library not loaded: libxxx.dylib
  2.   Referenced from: <BD86A23A-E5C5-35D0-BE6D-F9B966A01280> ..../build/xxxx
  3.   Reason: tried: 'libxxx.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibxxx.dylib' (no such file), 'libxxx.dylib' (no such file), '..../build/libxxx.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/..../build/libxxx.dylib' (no such file), '..../build/libxxx.dylib' (no such file)
  4. zsh: abort      ./xxxx
复制代码
缘故因由分析

运行
  1. man dyld
复制代码
可以看到以下文本
  1. DYLD_FALLBACK_LIBRARY_PATH
  2.        This is a colon separated list of directories that contain libraries.  If a dylib is not found at its
  3.        install  path, dyld uses this as a list of directories to search for the dylib.
  4.        For new binaries (Fall 2023 or later) there is no default.  For older binaries, their is a default fallback
  5.        search path of: /usr/local/lib:/usr/lib.
复制代码
意思是说2023年秋之后,/usr/local/lib:/usr/lib不再是DYLD_FALLBACK_LIBRARY_PATH的默认值,以是造成了这个庞大的举动改变。
办理方法

将该情况变量export赋值,放到.bashrc/.zshrc在shell开启时主动实行(具体使用略)或在步调启动时手动声明,如
  1. DYLD_FALLBACK_LIBRARY_PATH=/usr/local/lib ./xxxx
复制代码
即可使步调加载到/usr/local/lib下的动态库,乐成运行。
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表