[英]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 nlopt
和brew 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:
CMAKE_BIN
環境變量指定的路徑(劇透警告:設置它不起作用),或/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.