27

I'm attempting to do a bundle update on my rails application but I get the following error:

Installing ffi (1.0.11) with native extensions Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues so that we can fix it. Thanks!
/Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:552:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

        /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb 
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
    --with-ffi_c-dir
    --without-ffi_c-dir
    --with-ffi_c-include
    --without-ffi_c-include=${ffi_c-dir}/include
    --with-ffi_c-lib
    --without-ffi_c-lib=${ffi_c-dir}/lib
    --with-libffi-config
    --without-libffi-config
    --with-pkg-config
    --without-pkg-config
/Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:931:in `block in have_header'
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:930:in `have_header'
    from extconf.rb:9:in `<main>'


Gem files will remain installed in /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/ffi-1.0.11 for inspection.
Results logged to /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/ffi-1.0.11/ext/ffi_c/gem_make.out
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:530:in `block in build_extensions'
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:505:in `each'
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:505:in `build_extensions'
    from /Users/Kyle/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:180:in `install'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/source.rb:90:in `block in install'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/rubygems_integration.rb:82:in `preserve_paths'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/source.rb:89:in `install'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/installer.rb:73:in `block in install_gem_from_spec'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/rubygems_integration.rb:97:in `with_build_args'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/installer.rb:72:in `install_gem_from_spec'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/installer.rb:56:in `block in run'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/installer.rb:55:in `run'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/installer.rb:12:in `install'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/cli.rb:271:in `update'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/vendor/thor.rb:263:in `dispatch'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/vendor/thor/base.rb:386:in `start'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/bin/bundle:13:in `<top (required)>'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/bin/bundle:19:in `load'
    from /Users/Kyle/.rvm/gems/ruby-1.9.3-p125/bin/bundle:19:in `<main>'

Any ideas?

Kyle Decot
  • 20,715
  • 39
  • 142
  • 263

11 Answers11

35

I ran into a problem similar to this yesterday.

I was able to resolve it using these steps:

https://github.com/carlhuda/bundler/blob/1-0-stable/ISSUES.md

Essentially, there was a problem with my bundle and clearing things out and rebuilding things from scratch resolved it.

The steps are repeated here:

# remove user-specific gems and git repos
rm -rf ~/.bundle/ ~/.gem/

# remove system-wide git repos and git checkouts
rm -rf $GEM_HOME/bundler/ $GEM_HOME/cache/bundler/

# remove project-specific settings and git repos
rm -rf .bundle/

# remove project-specific cached .gem files
rm -rf vendor/cache/

# remove the saved resolve of the Gemfile
rm -rf Gemfile.lock

# try to install one more time
bundle install

Although, given the message in the output text:

You have to install development tools first.

That makes me think you just may not have installed the Apple Xcode Developer Tools. Have you checked that? (I believe they're available in the Mac App Store.)

Kevin Bedell
  • 13,254
  • 10
  • 78
  • 114
  • 2
    I do have Xcode installed but it appears that bundler can't find it for some reason...I tried your suggestions as well as installing https://github.com/kennethreitz/osx-gcc-installer and now everything works just fine. Thanks for the help! I plan on giving you the bounty but SO is making me wait 23 hours. I'll give it to you then :) – Kyle Decot May 16 '12 at 02:02
  • For me the problem was that I had Xcode installed, but I had not agreed to the license agreement yet. Executing gcc form the command line first (as root) and accepting the license agreement fixed the problem. After that the native ffi extension compile without problem. – Hardy Nov 07 '13 at 09:47
  • ffi is a bit confusing here because it will show many signs that GCC throwing errors. @Kevin's solution actually did the trick as my issues with ffi were in fact caused by Bundler. PS first command for me was actually: rm -rf ~/.bundler/ ~/.gem – Matt Jensen Feb 14 '14 at 02:47
  • gcc -v -> "Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo." -> You need to start XCode after update them. – a0s Sep 24 '14 at 11:13
  • If you have some Xcode related problems, you have to do it before bundling to get rid of the error – Joe Half Face Nov 16 '20 at 15:37
12

For Xcode 5 and later:

$ xcode-select --install

to install the Command Line Tools.

Lasse Bunk
  • 1,848
  • 20
  • 21
11

Once installed gcc-4.2 from brew, you need to create symlink of it:

ln -s /usr/bin/gcc /usr/bin/gcc-4.2
kiero
  • 121
  • 1
  • 4
  • This is what finally did it for me to install the eventmachine gem. I had tried updating rvm, reinstall ruby, making sure command line tools were in XCode (4.6) and bunch of other stuff. I tried setting CC=/usr/local/bin/gcc-4.2 and without that, but it seems like it ended up compiling with llvm-gcc since now "/usr/bin/gcc-4.2@ -> /usr/bin/gcc" and "/usr/bin/gcc@ -> llvm-gcc-4.2". I'm totally confused as to why, but it worked. Hopefully it doesn't mess anything else up like brew installs... – mmrobins Feb 06 '13 at 20:13
  • For me, I simply updated my XCode and command line tools followed by your suggestion to symlink to /usr/bin/gcc-4.2. Thanks! I wouldn't have figured that out for awhile. – David Vezzani Mar 28 '13 at 14:33
  • Tried installing XCode command line tools and running `gem install ffi` without success. After adding symlink as suggested by @kiero ffi-1.9.3 installed fine. Thanks! – Lenart Dec 16 '13 at 08:43
  • please see my answer below - it is bad to override existing symlinks when you can easily set CC (c compiler) with gem install – random-forest-cat Mar 25 '15 at 19:05
7

For me I just didn't have gcc installed, solve in Ubuntu by:

sudo apt install build-essential
Konstantin Pereiaslov
  • 1,786
  • 1
  • 18
  • 26
5

Just in case try to run

sudo /usr/bin/gcc

You'll probably see license agreement, so scroll thgough it, type "agree" and try to install gem again.

DiS
  • 61
  • 1
  • 1
5

Please note:

If you have recently updated Xcode, you may just need to open Xcode and accept the latest agreement.

I had the same issue and had recently installed an update to Xcode (v6.1) and solved it with these steps:

  1. open Xcode
  2. accept new agreement
  3. rerun bundle update
theotherjim
  • 51
  • 1
  • 2
4

Installing "Command Line Tools" via Xcode did the trick.

If you have Xcode 4.5 open Preferences > Downloads > Select Components tab and click Install next to Command Line Tools.

Although I installed from Xcode, you can also download the package without it from Apple's Developer Downloads and searching for "Command Line Tools".

Dan Sandland
  • 7,095
  • 2
  • 29
  • 29
1

I had to accept the Xcode User licence:

Running sudo xcrun cc should bring up the cli version of the Xcode license agreement. Another option is to open Xcode.app and agree in the GUI.

Possibly caused by updating OSX.

http://blog.tomhennigan.co.uk/post/62238548037/agreeing-to-the-xcode-license-from-the-command

i.bajrai
  • 87
  • 5
0

Mac OSx 10.10.2 yosemite

 CC=/usr/bin/i686-apple-darwin11-llvm-gcc-4.2 gem install ffi

and thats it -check that you have 4.2 compiler in /usr/bin that you can hook into

ls /usr/bin|grep gcc|grep 4.2

You do not have to wipe out all of your local gems or override symlinks to do this - its a waste of time and will likely create more problems then it solves.

please note, your bin path may be different if you needed to install via brew

brew install apple-gcc42 
random-forest-cat
  • 33,652
  • 11
  • 120
  • 99
0

Also method:

export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
bundle update

ffi.h is to be found in ${SDKROOT}/usr/include/ffi/ffi.h.

Gracjan Polak
  • 596
  • 3
  • 16
0

Ubuntu Trusty LTS 14.04

Needed to switch from ruby 2.2.1 to 2.3.0 to support newer gem versions in Rails app.

Solution:

  1. rvm get stable
  2. rvm remove 2.3.0
  3. rvm install 2.3.0
  4. bundle install
Alex M.
  • 43
  • 1
  • 2
  • 6