繁体   English   中英

如何在 Apple Silicon (M1) Mac 上安装 RcppArmadillo

[英]How to install RcppArmadillo on Apple Silicon (M1) Macs

我一直在尝试许多不同的方法来安装 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’

显然,我没有x86_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           

我想我发现了一个问题。 首先,我遵循本教程: R COMPILER TOOLS FOR RCPP ON MACOS
完成后,它给了我几乎与您在帖子中提到的相同的错误:

ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/.....'
ld: library not found for -lgfortran clang: error: linker command failed
with exit code 1 (use -v to see invocation)

看来,R 正在/opt/R/arm64文件夹中寻找 gfortran。
在教程中,它表示 gfortran 安装在/usr/local/gfortran文件夹中。
我在/opt/R/arm64中创建了一个符号链接,它使用命令引用/usr/local/gfortran
ln -s /usr/local/gfortran /opt/R/arm64

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

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

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

此外,可能还想将F77FC定义为

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

为了验证,尝试安装glmnet package 现在应该成功了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM