我正在尝试在 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。我已经安装了arm64版本的R。这是我当前的版本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
在我的机器(运行 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")
安装 CMake 后,
brew install cmake
成功。
至于您最初遇到的问题
gfortran
,我可能建议尝试我的说明这里。 R 建议安装特定版本的 gfortran
并配置编译器以通过 ~/.R/Makevars
查找该安装。你真的不需要弄乱你的PATH
...
不幸的是,
brew install cmake
没有帮助我,从源代码安装nloptr
也没有帮助我,配置RStudio以使用正确的PATH
也没有帮助我。
根据文档,在标记为安装 CMake(仅限 macOS 和 Linux) 的部分中,nloptr 软件包安装程序期望在以下位置找到
cmake
可执行文件:
CMAKE_BIN
/Applications/CMake.app/Contents/bin/cmake
shell 中解决问题的方法:
zsh
这种方法的缺点是它会将非应用程序放入
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
并将其重新安装为木桶
brew remove cmake
cask安装使用MacOS官方cmake包,由R拾取。