I'm trying to install the "lme4" library in R and RStudio, which worked before I was on an M1 Mac, but now it's not installing. The dependency that's having trouble is: "nloptr". Here's my current error:
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’ ```
I'm on an M1 Mac with Monterey (12.1). I've installed the arm64 version of R. Here's my current version 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
I've already tried the following in Terminal: brew install nlopt
and brew install gcc
.
Before this, I also had an error as follows:
ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0'
To fix that, based on Googling, I did this
export PATH=$PATH:/opt/R/arm64/gfortran/bin
and this
ln -sfn `xcrun --show-sdk-path` /opt/R/arm64/gfortran/SDK
On my machine (an M1 Mac running Big Sur), I've just tried install.packages("nloptr")
without first doing brew install nlopt
.
I get the same warning about -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’
but prior to the warning I see:
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")
succeeds after I install CMake with brew install cmake
.
As for your initial issue with gfortran
, I might suggest trying my instructions here. R recommends installing a specific build of gfortran
and configuring compilers to find that installation via ~/.R/Makevars
. You really should not need to mess with your PATH
...