-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Installing Rcpp Packages on M2 Mac: Fixing gfortran Dependencies
Problem Description
When trying to install R packages that use Rcpp and RcppArmadillo on an M2 Mac, you might encounter linking errors related to gfortran. This typically occurs when building packages that require LAPACK/BLAS linear algebra operations. The error message might look something like this:
ld: warning: search path '/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0' not found
ld: warning: search path '/opt/gfortran/lib' not found
ld: library 'gfortran' not found
clang++: error: linker command failed with exit code 1
Solution Using Homebrew
1. Install gcc/gfortran
First, install gcc (which includes gfortran) using Homebrew:
brew install gcc2. Verify Installation
You can verify that gfortran was installed correctly by checking its location and version:
# Check location
which gfortran
# Should show: /opt/homebrew/bin/gfortran
# Check version
gfortran --version3. Configure R to Use Homebrew's gfortran
Create or modify your R Makevars file:
# Create ~/.R directory if it doesn't exist
mkdir -p ~/.R
# Create or modify Makevars
touch ~/.R/MakevarsAdd the following lines to ~/.R/Makevars:
FLIBS=-L/opt/homebrew/lib/gcc/current -lgfortran -lquadmath
4. Rebuild Your Package
After setting up gfortran, rebuild your R package
Metadata
Metadata
Assignees
Labels
No labels