Mac M3 Sonoma14.5下RcppArmadillo提示gfortran未找到如何解决?
Rcpp/RcppArmadillo提示gfortran未找到但系统已安装的解决方法
问题描述
运行sourceCpp()执行Rcpp程序时触发链接错误:
ld: warning: search path '/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0' not found
ld: library 'gfortran' not found
但系统已安装GNU Fortran 13.2.0,验证输出:
GNU Fortran (GCC) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
中间排查步骤
- 2025年3月21日:通过Homebrew重装R和RStudio,Rcpp可正常运行,但RcppArmadillo仍报相同的gfortran未找到错误。
最终解决方案
2025年3月22日完成以下操作后问题解决:
- 在R控制台执行命令获取gfortran的实际路径:
system("which gfortran") - 打开R的配置文件:
file.edit(file.path(R.home("etc"), "Makeconf")) - 在打开的文件中找到
FC和FLIBS配置项,将其值修改为步骤1中得到的gfortran路径,保存文件后重启R即可。
内容的提问来源于stack exchange,提问作者FAM
相关产品推荐
相关产品推荐

