You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R加载asreml包失败:gcc旧路径查找问题求助

加载asreml包时动态库依赖错误的解决方案

问题详情

加载asreml包时触发以下错误:

> library(asreml)
Error: package or namespace load failed for ‘asreml’:
 .onLoad failed in loadNamespace() for 'asreml', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/asreml/libs/asreml.so':
  dlopen(/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/asreml/libs/asreml.so, 0x0006): Library not loaded: '/opt/homebrew/opt/gcc@11/lib/gcc/11/libgfortran.5.dylib'
  Referenced from: '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/asreml/libs/asreml.so'
  Reason: tried: '/opt/homebrew/opt/gcc@11/lib/gcc/11/libgfortran.5.dylib' (no such file), '/usr/local/lib/libgfortran.5.dylib' (no such file), '/usr/lib/libgfortran.5.dylib' (no such file)

此前卸载重装包可解决问题,但本次无效。当前环境中/opt/homebrew/opt/gcc@11/与/opt/homebrew/opt/gcc@12/均链接到../Cellar/gcc/12.2.0,使用的gcc版本为12。

可行解决方案

1. 创建缺失路径的符号链接

asreml依赖的库路径/opt/homebrew/opt/gcc@11/lib/gcc/11不存在,手动创建符号链接指向现有gcc12的对应目录:

# 创建必要的父目录
mkdir -p /opt/homebrew/opt/gcc@11/lib/gcc
# 建立符号链接
ln -s /opt/homebrew/opt/gcc@12/lib/gcc/12 /opt/homebrew/opt/gcc@11/lib/gcc/11

2. 临时设置环境变量引导库查找

在启动R前,将gcc12的库目录加入DYLD_LIBRARY_PATH:

export DYLD_LIBRARY_PATH=/opt/homebrew/opt/gcc@12/lib/gcc/12:$DYLD_LIBRARY_PATH
# 启动R
R

若有效,可将上述export命令添加到~/.zshrc或~/.bashrc中实现永久生效。

3. 安装gcc@11提供对应依赖库

若gcc12的库中无libgfortran.5.dylib,直接通过brew安装gcc@11:

brew install gcc@11

此操作会安装gcc11的完整依赖库,包含asreml需要的libgfortran.5.dylib。

4. 修改asreml.so的依赖路径

直接修改asreml.so中引用的库路径,指向当前gcc12的库文件:

# 先定位gcc12中libgfortran.5.dylib的路径
find /opt/homebrew/opt/gcc@12 -name "libgfortran.5.dylib"
# 替换为实际找到的路径,执行修改命令
install_name_tool -change /opt/homebrew/opt/gcc@11/lib/gcc/11/libgfortran.5.dylib /opt/homebrew/opt/gcc@12/lib/gcc/12/libgfortran.5.dylib /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/asreml/libs/asreml.so

内容的提问来源于stack exchange,提问作者Lindsey Schwartz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 10:10:40