rubyrvmmacos-big-sur

RVM install ruby 2.6.4 fails with makefile error: implicit declaration of function 'ffi_prep_closure' is invalid in C99


RVM rvm 1.29.12-next

macOS v11 (Big Sur) on an 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);

Solution

  • 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 environment variables 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 Z shell (executable 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 and reopen your terminal window or source ~/.zshrc to load your changes.

    Check your work with:

    echo $LDFLAGS
    

    Output:

    -L/opt/homebrew/opt/libffi/lib
    

    echo $CPPFLAGS
    

    Output:

    -I/opt/homebrew/opt/libffi/include
    

    echo $PKG_CONFIG_PATH
    

    Output:

    /opt/homebrew/opt/libffi/lib/pkgconfig
    

    (confirm that the environment variables are correct)

    Retry to install the rvm version you want to install.