rubyrubygemsjekyllmacos-catalinalibffi

Issues building the libffi gem native extension when trying to install Jekyll on macOS Catalina


EDIT: I wrote up a more detailed solution on my blog here if you want to walk through all the steps.

I'm trying to install Jekyll via gem install Jekyll on macOS Catalina using Ruby install via homebrew and located at /usr/local/opt/ruby/bin/ruby and I'm running into the following error

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/Users/foobar/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ffi-1.9.21/ext/ffi_c
/Users/foobar/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20181118-49440-k8mjki.rb
extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi... no
checking for shlwapi.h... no
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_call_without_gvl()... yes
creating extconf.h
creating Makefile

current directory:
/Users/foobar/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ffi-1.9.21/ext/ffi_c
make "DESTDIR=" clean

current directory:
/Users/foobar/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ffi-1.9.21/ext/ffi_c
make "DESTDIR="
Running autoreconf for libffi
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal -I m4 --output=aclocal.m4t
Can't exec "aclocal": No such file or directory at
/usr/local/Cellar/autoconf/2.69/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory
make: ***
["/Users/foobar/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ffi-1.9.21/ext/ffi_c/libffi-x86_64-darwin18"/.libs/libffi_convenience.a]
Error 1

make failed, exit code 2

Gem files will remain installed in
/Users/foobar/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ffi-1.9.21 for inspection.
Results logged to
/Users/foobar/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0-static/ffi-1.9.21/gem_make.out

An error occurred while installing ffi (1.9.21), and Bundler cannot continue.

I've already tried updating my Xcode Command Line tools via xcode-select --install but I got back the following message:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

Does anyone know how I can build libffi on my machine so that I Jekyll can use it as a dependency?


Solution

  • Aaaaaand I figured it out! Credit to @ffleming here. Here's what you need to do:

    1. reinstall libffi on brew using brew reinstall libffi
    2. add the new brew-installed libffi flags to your shell instance, e.g.
    export LDFLAGS="-L/usr/local/opt/libffi/lib"
    export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
    
    1. Run gem install jekyll and you should be sorted!