繁体   English   中英

在 M1 mac 上安装 R package “nloptr”时出现问题

[英]Problems installing R package "nloptr" on M1 mac

我正在尝试在 R 和 RStudio 中安装“lme4”库,这在我使用 M1 Mac 之前就可以使用,但现在它没有安装。 有问题的依赖是:“nloptr”。 这是我当前的错误:

clang++ -arch arm64 -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o nloptr.so init_nloptr.o nloptr.o test-C-API.o test-runner.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lm -Lnlopt/lib -lnlopt -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-Lnlopt/lib'
ld: library not found for -lnlopt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [nloptr.so] Error 1
ERROR: compilation failed for package ‘nloptr’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/nloptr’
Warning in install.packages :
  installation of package ‘nloptr’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/ht/y6qd6yfn67x086jtwxvh42tw0000gn/T/RtmpULtpZq/downloaded_packages’ ```

我正在使用 Monterey (12.1) 的 M1 Mac。 我已经安装了 R 的 arm64 版本。 这是我当前的版本 R 4.1.2:

> version
               _                           
platform       aarch64-apple-darwin20      
arch           aarch64                     
os             darwin20                    
system         aarch64, darwin20           
status                                     
major          4                           
minor          1.2                         
year           2021                        
month          11                          
day            01                          
svn rev        81115                       
language       R                           
version.string R version 4.1.2 (2021-11-01)
nickname       Bird Hippie    

我已经在终端中尝试过以下操作: brew install nloptbrew install gcc

在此之前,我也遇到如下错误: ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0'修复那,基于谷歌搜索,我做了这个export PATH=$PATH:/opt/R/arm64/gfortran/bin和这个ln -sfn `xcrun --show-sdk-path` /opt/R/arm64/gfortran/SDK

不幸的是brew install cmake没有帮助我,也没有从源代码安装nloptr ,也没有配置 RStudio 使用正确的PATH

According to the documentation , in the section labeled Installing CMake (macOS and Linux only) , the nloptr package installer expects to find the cmake executable either at:

  1. CMAKE_BIN环境变量指定的路径(剧透警告:设置它不起作用),或
  2. /Applications/CMake.app/Contents/bin/cmake

这是我最终在zsh shell 中解决问题的方法:

brew install cmake
sudo mkdir -p /Applications/cmake.app/Contents/bin
cd /Applications/cmake.app/Contents/bin
sudo ln -s /opt/homebrew/bin/cmake

这种方法的缺点是它在/Applications目录中放置了一个非应用程序,但我可以接受。

在我的机器(运行 Big Sur 的 M1 Mac)上,我刚刚尝试了install.packages("nloptr") ,而没有先执行brew install nlopt

我收到关于-Lnlopt/lib的相同警告:

ld: warning: directory not found for option '-Lnlopt/lib'
ld: library not found for -lnlopt
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [nloptr.so] Error 1
ERROR: compilation failed for package ‘nloptr’

但在警告之前我看到:

checking if pkg-config knows NLopt... no
using NLopt via local cmake build on arm64

------------------ CMAKE NOT FOUND --------------------

CMake was not found on the PATH. Please install CMake:

 - yum install cmake          (Fedora/CentOS; inside a terminal)
 - apt install cmake          (Debian/Ubuntu; inside a terminal).
 - pacman -S cmake            (Arch Linux; inside a terminal).
 - brew install cmake         (MacOS; inside a terminal with Homebrew)
 - port install cmake         (MacOS; inside a terminal with MacPorts)

Alternatively install CMake from: <https://cmake.org/>

-------------------------------------------------------

install.packages("nloptr")在我用brew install cmake安装 CMake 后成功。

至于您最初使用gfortran的问题,我可能会建议您在此处尝试我的说明。 R 建议安装特定版本的gfortran并配置编译器以通过~/.R/Makevars找到该安装。 你真的不需要弄乱你的PATH ......

暂无
暂无

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

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