Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

building from source on Apple M1 and M2 computers #145

Open
ajrominger opened this issue Feb 13, 2025 · 0 comments
Open

building from source on Apple M1 and M2 computers #145

ajrominger opened this issue Feb 13, 2025 · 0 comments

Comments

@ajrominger
Copy link
Member

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 gcc

2. 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 --version

3. 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/Makevars

Add 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant