18

RVM rvm 1.29.12-next

Mac OS Big Sur on M1 chip

rvm install 2.6.4 fails with:

Error running '__rvm_make -j8',
please read /Users/jason/.rvm/log/1626110300_ruby-2.6.4/make.log

There has been an error while running make. Halting the installation.

the makefile error is:

error: implicit declaration of function 'ffi_prep_closure' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    result = ffi_prep_closure(pcl, cif, callback, (void *)self);
Jason FB
  • 4,752
  • 3
  • 38
  • 69

2 Answers2

32

this is caused by the environment flags not being set in your shell.

you need to run brew install libffi, but to do that, the env vars must be set in your shell

brew info libffi

will tell you the variables you need:

For compilers to find libffi you may need to set:

export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include"

For pkg-config to find libffi you may need to set:

export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig"

for ZSH, edit ~/.zshenv and add:

export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig"

Close & reopen your terminal window or source ~/.zshrc to load your changes

Check your work with

% echo $LDFLAGS
-L/opt/homebrew/opt/libffi/lib
% echo $CPPFLAGS
-I/opt/homebrew/opt/libffi/include
% echo $PKG_CONFIG_PATH
/opt/homebrew/opt/libffi/lib/pkgconfig

(confirm that the environment variables are correct)

re-try to install the rvm version you want to install.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
Jason FB
  • 4,752
  • 3
  • 38
  • 69
  • 2
    Worked for macos big sur 11.4 with M1 and ruby 2.7.0. Make sure you install libffi with `brew install libffi` to see the required variables. – F.E.A Jul 26 '21 at 09:33
  • 1
    Also worked for `rbenv` ruby installations. – anka Jun 13 '22 at 08:53
  • Thanks, this worked with `rvm` and Ruby 3.0.0. I want to reiterate that you need to actually `brew install libffi` and copy the specific env vars and paths for your system as opposed to just copy pasting the ones above. – Casey L Jan 11 '23 at 16:55
  • @CaseyL - clarified, thank you – Jason FB Jan 11 '23 at 19:28
1

[M1 Pro with 12.3 Monterey]

It got resolved in my case with below commands.

brew install libffi

And setting variables to .zshenv file.

export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include"

Close terminal and open new one OR source ~/.zshrc

Run the below command now.

rvm install 2.6.4