26

我正在尝试bundle update在我的 Rails 应用程序上进行操作,但出现以下错误:

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>'

有任何想法吗?

4

11 回答 11

33

我昨天遇到了类似的问题。

我能够使用以下步骤解决它:

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

本质上,我的捆绑包存在问题,清理并从头开始重建东西解决了它。

此处重复这些步骤:

# 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

虽然,鉴于输出文本中的消息:

您必须先安装开发工具。

这让我觉得你可能没有安装Apple Xcode Developer Tools。你检查过吗?(我相信它们可以在 Mac App Store 中找到。)

于 2012-05-16T01:40:38.480 回答
12

对于 Xcode 5 及更高版本:

$ xcode-select --install

安装命令行工具。

于 2013-11-02T14:23:29.147 回答
11

从 brew 安装 gcc-4.2 后,您需要创建它的符号链接:

ln -s /usr/bin/gcc /usr/bin/gcc-4.2
于 2012-10-12T00:13:31.550 回答
7

对我来说,我只是没有安装 gcc,在 Ubuntu 中通过以下方式解决:

sudo apt install build-essential
于 2016-07-26T11:03:32.407 回答
5

以防万一尝试运行

须藤/usr/bin/gcc

您可能会看到许可协议,因此滚动浏览它,输入“agree”并尝试再次安装 gem。

于 2014-09-25T02:51:25.810 回答
5

请注意:

如果您最近更新了 Xcode,您可能只需要打开 Xcode 并接受最新协议即可。

我遇到了同样的问题,最近安装了 Xcode (v6.1) 的更新并通过以下步骤解决了它:

  1. 打开 Xcode
  2. 接受新协议
  3. 重新运行捆绑更新
于 2015-02-12T17:01:17.050 回答
4

通过 Xcode 安装“命令行工具”就可以了。

如果您有 Xcode 4.5,请打开Preferences > Downloads > Select Components选项卡,然后单击Command Line Tools旁边的Install

虽然我是从 Xcode 安装的,但您也可以从Apple 的 Developer Downloads 并搜索“命令行工具”下载没有它的软件包。

于 2012-11-26T03:19:58.250 回答
1

我必须接受 Xcode 用户许可证:

运行 sudo xcrun cc 应该会调出 Xcode 许可协议的 cli 版本。另一种选择是打开 Xcode.app 并在 GUI 中同意。

可能是由更新 OSX 引起的。

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

于 2015-09-29T07:02:37.057 回答
0

Mac OSx 10.10.2 优胜美地

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

就是这样 - 检查你有 4.2 编译器/usr/bin,你可以挂钩

ls /usr/bin|grep gcc|grep 4.2

您不必清除所有本地 gem 或覆盖符号链接来执行此操作- 这是浪费时间,并且可能会产生更多问题然后解决。

请注意,如果您需要通过 brew 安装,您的 bin 路径可能会有所不同

brew install apple-gcc42 
于 2015-03-25T19:03:59.690 回答
0

还有方法:

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

ffi.h将在 中找到${SDKROOT}/usr/include/ffi/ffi.h

于 2015-05-22T15:31:02.223 回答
0

Ubuntu 可信赖 LTS 14.04

需要从 ruby​​ 2.2.1 切换到 2.3.0 以支持 Rails 应用程序中较新的 gem 版本。

解决方案:

  1. rvm get stable
  2. rvm remove 2.3.0
  3. rvm install 2.3.0
  4. bundle install
于 2016-04-26T08:57:49.920 回答