61

Can't install specific ffi version. If I run gem install ffi, everything works just fine but I need specific version 1.9.18 and it doesn't work.

Fetching ffi 1.9.18
Installing ffi 1.9.18 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /Users/chille/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ffi- 
1.9.18/ext/ffi_c
/Users/chille/.rbenv/versions/2.6.5/bin/ruby -I 
/Users/chille/.rbenv/versions/2.6.5/lib/ruby/2.6.0 -r
./siteconf20200928-22154-72wopi.rb extconf.rb
checking for ffi_call() in -lffi... yes
checking for ffi_prep_closure()... yes
checking for ffi_raw_call()... yes
checking for ffi_prep_raw_closure()... yes
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
checking for ffi_prep_cif_var()... yes
creating extconf.h
creating Makefile

current directory: /Users/chille/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ffi- 
1.9.18/ext/ffi_c
make "DESTDIR=" clean

current directory: /Users/chille/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ffi- 
1.9.18/ext/ffi_c
make "DESTDIR="
compiling AbstractMemory.c
compiling ArrayType.c
compiling Buffer.c
compiling Call.c
Call.c:355:5: error: implicit declaration of function 'rb_thread_call_without_gvl' is 
invalid in C99
[-Werror,-Wimplicit-function-declaration]
rbffi_thread_blocking_region(call_blocking_function, data, (void *) -1, NULL);
^
./Thread.h:78:39: note: expanded from macro 'rbffi_thread_blocking_region'
# define rbffi_thread_blocking_region rb_thread_call_without_gvl
                                  ^
1 error generated.
make: *** [Call.o] Error 1

make failed, exit code 2

Gem files will remain installed in 

/Users/chille/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ffi-1.9.18 for inspection. Results logged to /Users/chille/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64- darwin-19/2.6.0/ffi-1.9.18/gem_make.out

An error occurred while installing ffi (1.9.18), and Bundler cannot continue. Make sure that gem install ffi -v '1.9.18' succeeds before bundling.

In Gemfile: bootstrap-sass was resolved to 3.3.7, which depends on sass was resolved to 3.5.5, which depends on sass-listen was resolved to 4.0.0, which depends on rb-inotify was resolved to 0.9.10, which depends on ffi

Denis Omerovic
  • 1,420
  • 1
  • 10
  • 23
  • According to ruby gems.org, that version is 3.5 years old. It doesn't appear to build against later versions of ruby (I recreated your error using ruby 2.7). What version of rails are you using? – rmlockerd Sep 28 '20 at 08:56
  • @rmlockerd Rails 5.1.7 and Ruby 2.6.5 – Denis Omerovic Sep 28 '20 at 09:14
  • All I had to do was `gem uninstall ffi` > `All versions`, then reinstall it via `bundle install`. The version which worked for me was `1.11.1` – GDP2 Jan 17 '21 at 23:53

5 Answers5

197

To get past that error, install ffi using:

gem install ffi -v '1.9.18' -- --with-cflags="-Wno-error=implicit-function-declaration"

NOTE: make sure to use the correct version of ffi in example above.

Shiva
  • 11,485
  • 2
  • 67
  • 84
user2066349
  • 2,439
  • 1
  • 15
  • 8
  • 1
    I had this same problem with noi4r and this worked for it as well! – Carl Dec 17 '20 at 22:11
  • 3
    `gem install ffi -v '1.14.2' -- --with-cflags="-Wno-error=implicit-function-declaration"`. I've been fighting this issue for a long time. Rails 6.1, ruby 3.0.0. – Greg Jan 06 '21 at 04:44
  • You don't know how long I have trying to get past this! – Robert_T_Taylor Jan 16 '21 at 04:04
  • bundler config to apply the same flag: `bundle config build.ffi --with-cflags="-Wno-error=implicit-function-declaration"`. I still think updating gems should be preferred, but I have some gems running into this issue where updating would require a major version bump (e.g. pg). If you do apply this to other gems, remember to change the gem name in the `build.ffi` config key to match the name of the problematic gem. – nar8789 Apr 17 '21 at 00:03
  • This worked for me, thanks. But isn't this just ignoring the error? Is there a solution that resolves the error? I'm not able to bump the ffi version right now. – Fralcon Jun 10 '21 at 20:55
22

if you want bundle install ffi 1.9.8

bundle config --local build.ffi --with-cflags=-Wno-error=implicit-function-declaration

bundle install
panaoke
  • 221
  • 2
  • 2
14

For those who can, I think bumping ffi version should be preferred here. bundle update ffi took me from from 1.9.18 to 1.13.1 and built successfully for me.

@denis-osmerovic, unless you have another dependency holding ffi back, you should also be able to bump ffi. Checking my dependency chain, my ffi dependency is also coming from rb-inotify 0.9.10, same as yours. The listed requirement is for ffi (>= 0.5.0, < 2), so 1.13.1 should be acceptable.

Other background:

I previously had a working copy of ffi 1.19.18, and I don't remember needing to pass any special build flags. In order to reproduce this I uninstalled and tried to reinstall that version. I'm guessing other library or toolchain updates in the meantime broke this.

I am running ruby 2.6.3 on OS X 10.15.7 alongside Xcode 12.0.1

nar8789
  • 727
  • 6
  • 9
  • 2
    This answer is underrated, thank you. I was working on an old repository and after many attempts at configuring ffi on a mac Big Slur development machine, a simple bump to 1.13.1 was the solution. – Shahin Hj Dec 11 '20 at 03:46
5

On an M1 Catalina 11.6, I was able to get past the error by first doing:

bundle update ffi

Then because I did not care about which version:

gem install ffi -- --with-cflags="-Wno-error=implicit-function-declaration"

If you need a version, other answers have that.

lordB8r
  • 370
  • 2
  • 12
-2

Due to the very nature of what the ffi gem does, it is tightly bound to the internals of the YARV engine. Therefore, you need to make sure you use a version of YARV that matches the version of the ffi gem.

In 2017, that would have been Ruby 2.4. Note that as of April 2020, Ruby 2.4 is no longer supported.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653