Efforts on resolving compiling issues upon installing R packages on the Mac M1 chip
1. Install Xcode
or Command Line Tool
Run the following from Terminal
:
xcode-select --install
If you get an error message: xcode-select: error: command line tools are already installed, use "Software Update" to install updates
, then you already have command line tools and can proceed to the next step. Else please follow the onscreen instructions and install it first.
2. Add the OpenMP runtime for clang
2.1 install libomp
Install homebrew
if you have not already. Run the following from Terminal
:
brew update && brew install libomp
2.2 OpenMP
run-time downloads
Run the following from the Terminal
:
curl -O https://mac.r-project.org/openmp/openmp-12.0.1-darwin20-Release.tar.gz
sudo tar fvxz openmp-12.0.1-darwin20-Release.tar.gz -C /
3. Enable OpenMP
3.1 Download the libomp
run-time corresponding to the Xcode version you use from the links above (Step1, 2 above)
Normally, you should find the following files:
usr/local/lib/libomp.dylib
usr/local/include/ompt.h
usr/local/include/omp.h
usr/local/include/omp-tools.h
3.2 Add -Xclang -fopenmp
to CPPFLAGS
, add -lomp
to LIBS
Add the following contents into you home directory ~/.R/Makevars
with your preferred text editor (create this file if you don’t have):
CPPFLAGS += -Xclang -fopenmp
LDFLAGS += -lomp
Note that the file is hidden by default, using shift+cmd+.
to show hidden files. Be very careful when doing this, always check your ~/.R/Makevars
whenever you upgrade R
, macOS
or Xcode
.
4. Verifying code signatures (optional)
Normally, it should be work here. You may want to verify the signatures via code tools. Run the following from Terminal
:
codesign -d -vv /usr/local/lib/libomp.dylib
Then you should see the output like this:
$ codesign -d -vv /usr/local/lib/libomp.dylib
Executable=/usr/local/lib/libomp.dylib
Identifier=libomp
Format=Mach-O universal (x86_64 arm64)
CodeDirectory v=20400 size=5514 flags=0x0(none) hashes=167+2 location=embedded
Signature size=8927
Authority=Developer ID Application: Simon Urbanek (VZLD955F6P)
Authority=Developer ID Certification Authority
Authority=Apple Root CA
Timestamp=11/11/2021 at 1:29:04 PM
Info.plist=not bound
TeamIdentifier=VZLD955F6P
Sealed Resources=none
Internal requirements count=1 size=168
5. Testing
Try to install packages to see if you succeed, for example:
install.packages(c("Rcpp", "data.table"), type = "source")
原文地址:http://www.cnblogs.com/res-daqian-lu/p/16849483.html