ERROR: Error installing ffi: ERROR: Failed to build gem native extension
Asked Answered
U

17

34

Got the DevKit installed and re-ran the ffi install….got this as an output:

C:\Documents and Settings\******>gem install ffi
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing ffi:
        ERROR: Failed to build gem native extension.

        C:/Ruby192/bin/ruby.exe extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include... no
checking for rb_thread_blocking_region()... yes
checking for ruby_thread_has_gvl_p()... yes
checking for ruby_native_thread_p()... yes
checking for rb_thread_call_with_gvl()... yes
creating extconf.h
creating Makefile
make
C:/Ruby192/bin/ruby -e "puts 'EXPORTS', 'Init_ffi_c'"  > ffi_c-i386-mingw32.def
gcc -I. -IC:/Ruby192/include/ruby-1.9.1/i386-mingw32 -I/C/Ruby192/include/ruby-1
.9.1/ruby/backward -I/C/Ruby192/include/ruby-1.9.1 -I. -DRUBY_EXTCONF_H=\"extcon
f.h\"    -O3 -g -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -
Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-declaration-a
fter-statement   -o AbstractMemory.o -c AbstractMemory.c
In file included from AbstractMemory.c:28:0:
compat.h:65:20: warning: extra tokens at end of #ifndef directive
compat.h:69:24: warning: extra tokens at end of #ifndef directive
In file included from AbstractMemory.h:29:0,
                 from AbstractMemory.c:29:
Types.h:68:17: fatal error: ffi.h: No such file or directory
compilation terminated.
make: *** [AbstractMemory.o] Error 1 

Gem files will remain installed in C:/Ruby192/lib/ruby/gems/1.9.1/gems/ffi-1.0.1
0 for inspection.
Results logged to C:/Ruby192/lib/ruby/gems/1.9.1/gems/ffi-1.0.10/ext/ffi_c/gem_m
ake.out
_________________________________________________________________________________

Not sure how to deal with this issue. Kindly help.

Undersell answered 21/10, 2011 at 16:42 Comment(0)
H
23

The gem install ffi fails due to the gem trying to build a bundled copy of libffi, which does not work due to assumptions that /usr/bin/env exists and too old libffi copy.

However, you can build the ffi gem against the system libffi - install the packages:

apt install clang make ruby-dev libffi-dev

After that the ffi gem should build:

gem install ffi
Handcraft answered 11/5, 2017 at 22:23 Comment(1)
What about macos?Christadelphian
A
17
sudo apt-get install libffi-dev

This worked for me

Avenue answered 6/2, 2018 at 19:6 Comment(1)
This is what worked for me, as well, on a Linux Mint system. Here's a hint to future seekers (for what it's worth to posterity): a gem that won't automatically install generally requires, in my experience, the system's own package manager to install the 'dev' version of a related package.Endoderm
C
16

Version 1.0.10 has issues compiling on windows.

You can use the 1.0.9

gem install ffi --version='1.0.9'
Cytogenesis answered 26/10, 2011 at 14:10 Comment(3)
+1 thank you so much, this helped me install middleman on my Win7 boxClaqueur
ERROR: Error installing railties: ERROR: Failed to build gem native extension.Praise
Is the error happening with the same ruby and ffi version which Windows OS?Cytogenesis
G
9

For me the fix was running in this order. I'm not sure what all was relevant, but it worked:

gem install ffi --version '1.0.9'

The above failed, but then I could successfully run:

gem install bundler

...and subsequently:

gem install ffi

...which got the latest version (1.6.0 at the time of writing this) and installed it successfully.

Gravelblind answered 27/3, 2013 at 15:23 Comment(1)
Thanks a million!Dickens
A
7

when the above steps are followed, it might results the following message.

$ bundle install
Fetching source index for https://rubygems.org/
You have requested:
ffi = 1.0.9

The bundle currently has ffi locked at 1.0.11.
Try running `bundle update ffi`

In that case, you can run the 'bundle update ffi' command and the error will be solved.

Acne answered 21/2, 2012 at 10:41 Comment(1)
bundle update ffi worked for me, thanks.Coadunate
A
6

Note that installing version 1.0.9 isn't going to be enough if your bundler keeps trying to go out and grab the latest version. In your gemfile you'll also want to put:

gem 'ffi', '1.0.9'

This should satisfy the dependency for whatever gem is asking for it and let you get up and running.

Aglet answered 5/12, 2011 at 18:14 Comment(0)
M
4

Installing the 'osx-gcc-installer' worked for me: (osx 10.8)

https://github.com/kennethreitz/osx-gcc-installer/downloads

Metamorphose answered 27/8, 2012 at 19:43 Comment(3)
the environment used for the question is windowsCytogenesis
Newer versions of macOS may simply xcode-select --install to get the compilers.Hadhramaut
This link is not workingElum
L
4

Helped me:

sudo apt install build-essential

Debian 9

Ruby 2.3.3

Lukewarm answered 28/2, 2020 at 12:37 Comment(0)
S
4

For me, this usually works

gem install ffi -- --disable-system-libffi
Sainfoin answered 23/10, 2020 at 15:22 Comment(1)
This works when installing the gem by itself, but not if ffi is being installed by bundle install.Kinny
H
3

you need this,

apt-get install ruby2.2-dev
Hargreaves answered 14/7, 2015 at 21:48 Comment(0)
C
2

Copied from another post:

As stated in Issue with installing ImageMagick and rmagick on Mountain Lion, ffi appears to be configured to look for 'gcc-4.2', so once I updated my Apple command line tools (which I may or may not have needed to do), I created a symbolic link to make the ffi install configuration happy:

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
Clovah answered 28/3, 2013 at 14:36 Comment(1)
Worked perfectly after I installed the Apple CLI tools.Gooseherd
K
2

This worked for me gem install ffi -- --disable-system-libffi on Ubuntu 20.04 (WSL)

Kaffir answered 22/12, 2020 at 0:42 Comment(1)
This works when installing the gem by itself, but not if ffi is being installed by bundle install.Kinny
T
1

On MacOS (Catalina), running brew install libtool first solved the problem for me.

Telophase answered 10/4, 2020 at 15:53 Comment(0)
W
0

Put DevKit in front of your PATH, and install again from Windows command prompt.

Wrapper answered 7/2, 2013 at 0:26 Comment(0)
I
0

I got the same problem. In my case, I have not install the DevKit, which can be found: http://rubyinstaller.org/downloads/. After installing DevKit, just follow the instruction https://github.com/oneclick/rubyinstaller/wiki/development-kit and finally it's up and running.

Ignatz answered 6/8, 2013 at 14:17 Comment(0)
L
0

I had to install automake to get it working. Worked on both mac OSX as well as Ubuntu (CI machine).

Letti answered 16/2, 2018 at 22:32 Comment(0)
A
0

Run this: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then: brew install cocoapods

Archaism answered 13/11, 2022 at 13:17 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Will

© 2022 - 2024 — McMap. All rights reserved.