0

我正在尝试安装 ffi gem,以便可以使用命令来使用guard-rspec sudo gem install ffi -v '1.9.8'。我最终得到这个输出:

Building native extensions.  This could take a while...
ERROR:  Error installing ffi:
    ERROR: Failed to build gem native extension.

    /usr/local/bin/ruby -r ./siteconf20150424-14771-zza3du.rb extconf.rb
*** 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
    --without-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=/usr/local/bin/$(RUBY_BASE_NAME)
    --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
/usr/local/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/local/lib/ruby/2.2.0/mkmf.rb:541:in `try_link0'
    from /usr/local/lib/ruby/2.2.0/mkmf.rb:556:in `try_link'
    from /usr/local/lib/ruby/2.2.0/mkmf.rb:637:in `try_ldflags'
    from /usr/local/lib/ruby/2.2.0/mkmf.rb:1780:in `pkg_config'
    from extconf.rb:15:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /usr/local/lib/ruby/gems/2.2.0/gems/ffi-1.9.8 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/ffi-1.9.8/gem_make.out

mkmf.log 文件如下所示:

"/usr/local/bin/gcc -o conftest -I/usr/local/include/ruby-2.2.0/x86_64-darwin14 -I/usr/local/include/ruby-2.2.0/ruby/backward -I/usr/local/include/ruby-2.2.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat  -pipe conftest.c  -L. -L/usr/local/lib -L. -fstack-protector     -lruby-static -framework CoreFoundation  -lpthread -lgmp -ldl -lobjc "
sh: line 1: 14464 Trace/BPT trap: 5       /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk / -find dsymutil 2> /dev/null
dsymutil: error: unable to find utility "dsymutil", not a developer tool or in PATH
collect2: error: dsymutil returned 72 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

所以 mkmf.rb 似乎在抱怨找不到 dsymutil。但是命令/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk / -find dsymutil给出了输出

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil

所以问题不在于我没有安装命令行工具。

我决定看一下 mkmf.rb 的源代码,看看我是否能弄清楚发生了什么。引发错误的方法是:

  def try_do(src, command, *opts, &b)
      unless have_devel?
        raise <<MSG
The compiler failed to generate an executable file.
You have to install development tools first.
MSG
      end
      begin
        src = create_tmpsrc(src, &b)
        xsystem(command, *opts)
      ensure
        log_src(src)
        MakeMakefile.rm_rf "#{CONFTEST}.dSYM"
      end
    end

have_devel?所以我们可以看到,如果方法返回 false ,就会引发错误。现在检查一下:

$ irb
irb(main):001:0> require 'mkmf'
=> true
irb(main):002:0> have_devel?
=> true

伟大的。所以ruby可以找到我的命令行工具。但如果我以 root 身份运行 irb:

$ sudo irb
Password:
irb(main):001:0> require 'mkmf'
=> true
irb(main):002:0> have_devel?
=> false

它失败。吐出的 mkmf.log 文件与上面的相同,抱怨缺少 dsymutil。我不知道为什么会这样。

有人对我如何安装 ffi 有任何建议吗?我怀疑我的盒子有些奇怪,没有人能够重现这种 mkmf 行为。

4

0 回答 0