首页 > 解决方案 > 如何在 Apple Silicon (M1) Mac 上安装 RcppArmadillo

问题描述

我一直在尝试许多不同的方法来安装 RcppArmadillo,但我没有让它工作

install.packages(c('Rcpp'))
Sys.setenv("PKG_CXXFLAGS"="-std=c++11")
install.packages(c('RcppArmadillo'),type = "source")

它给了我这个错误:

ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin18/8.2.0'
ld: library not found for -lquadmath
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [RcppArmadillo.so] Error 1
ERROR: compilation failed for package ‘RcppArmadillo’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo’

显然,自从我为 Apple Silicon Architecturex86_64-apple-darwin18/8.2.0安装了 gfortran 之后,我就没有了。

Mac版:

macOS Big Sur 
11.2.3
Apple M1

R版本:

version
               _                           
platform       x86_64-apple-darwin17.0     
arch           x86_64                      
os             darwin17.0                  
system         x86_64, darwin17.0          
status                                     
major          4                           
minor          0.4                         
year           2021                        
month          02                          
day            15                          
svn rev        80002                       
language       R                           
version.string R version 4.0.4 (2021-02-15)
nickname       Lost Library Book           

标签: rmacosrcppapple-m1rcpparmadillo

解决方案


可以设置FLIBS~/.R/Makevars以下选项之一

# homebrew gfortran
FLIBS=-L/opt/homebrew/opt/gfortran/lib

# gfortran included in R
FLIBS=-L/opt/R/arm64/gfortran/lib

此外,可能还想将F77and定义FC

F77     = /opt/R/arm64/gfortran/bin/gfortran
FC      = /opt/R/arm64/gfortran/bin/gfortran

要验证,请尝试安装glmnet现在应该成功的包。


推荐阅读