安装unf_ext时安装时出错

时间:2017-09-27 17:25:48

标签: ruby macos

昨天我安装了MacOS High Sierra,我正在测试我的ruby代码,由于我的某个宝石没有安装,它失败了。我今天尝试安装它并将其取回:

Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/.
Using bundler 1.15.4
Fetching unf_ext 0.0.7.4


Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle install --path vendor/bundle

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to RubyGems using sudo.

  Password: 
Installing unf_ext 0.0.7.4 with native extensions
Using mime-types-data 3.2016.0521
Using net-http-digest_auth 1.4.1
Using net-http-persistent 2.9.4
Using mini_portile2 2.1.0
Using ntlm-http 0.1.1
Using webrobots 0.1.2
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/private/var/folders/lq/mdp176gx3b90j7_mvygpydmr0000gn/T/bundler20170927-4407-1gh3fizunf_ext-0.0.7.4/gems/unf_ext-0.0.7.4/ext/unf_ext
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r
./siteconf20170927-4407-1twnwgt.rb extconf.rb
checking for main() in -lstdc++... *** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/$(RUBY_BASE_NAME)
    --with-static-libstdc++
    --without-static-libstdc++
    --with-stdc++lib
    --without-stdc++lib
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:456:in
`try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:535:in
`block in try_link0'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/tmpdir.rb:89:in
`mktmpdir'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:532:in
`try_link0'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:556:in
`try_link'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:765:in
`try_func'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:997:in
`block in have_library'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:942:in
`block in checking_for'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:350:in
`block (2 levels) in postpone'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:320:in
`open'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:350:in
`block in postpone'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:320:in
`open'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:346:in
`postpone'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:941:in
`checking_for'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:992:in
`have_library'
    from extconf.rb:6:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

/var/folders/lq/mdp176gx3b90j7_mvygpydmr0000gn/T/bundler20170927-4407-1gh3fizunf_ext-0.0.7.4/extensions/universal-darwin-17/2.3.0/unf_ext-0.0.7.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/var/folders/lq/mdp176gx3b90j7_mvygpydmr0000gn/T/bundler20170927-4407-1gh3fizunf_ext-0.0.7.4/gems/unf_ext-0.0.7.4
for inspection.
Results logged to
/var/folders/lq/mdp176gx3b90j7_mvygpydmr0000gn/T/bundler20170927-4407-1gh3fizunf_ext-0.0.7.4/extensions/universal-darwin-17/2.3.0/unf_ext-0.0.7.4/gem_make.out

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

In Gemfile:
  mechanize was resolved to 2.7.5, which depends on
    http-cookie was resolved to 1.0.3, which depends on
      domain_name was resolved to 0.5.20170404, which depends on
        unf was resolved to 0.1.4, which depends on
          unf_ext

然后当我尝试安装unf_ext时会发生这种情况

sudo gem install unf_ext -v '0.0.7.4'
Building native extensions.  This could take a while...
ERROR:  Error installing unf_ext:
    ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.3.0/gems/unf_ext-0.0.7.4/ext/unf_ext
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20170927-4629-13u5zrr.rb extconf.rb
checking for main() in -lstdc++... *** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/$(RUBY_BASE_NAME)
    --with-static-libstdc++
    --without-static-libstdc++
    --with-stdc++lib
    --without-stdc++lib
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:535:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/tmpdir.rb:89:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:532:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:556:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:765:in `try_func'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:997:in `block in have_library'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:942:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:350:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:350:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:346:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:941:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:992:in `have_library'
    from extconf.rb:6:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-17/2.3.0/unf_ext-0.0.7.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/unf_ext-0.0.7.4 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-17/2.3.0/unf_ext-0.0.7.4/gem_make.out

我不知道问题是什么。我安装了ruby和rbenv,但是一旦我安装了新的MacOs,我就无法安装任何宝石。

2 个答案:

答案 0 :(得分:0)

它告诉你错误,你只需要选择输出。

checking for main() in -lstdc++... *** extconf.rb failed ***

extconf.rb是为本机编译配置gem的脚本,这里它检查一个非常基本的要求:你能编译一个C ++可执行文件吗?它失败了。稍后它会重复这个

mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.

mkmf.rbextconf.rb用于测试编译器功能的stdlib,然后输出合适的makefile来构建扩展。它重复它甚至无法构建C ++可执行文件(更不用说检查任何特定的功能)。

因此,要么您没有安装C ++编译器,要么您的路径没有以Ruby可以找到的方式设置。

答案 1 :(得分:0)

我将“ extconf.rb”复制到我的工作文件夹中,然后再次运行“ ruby​​ extconf.rb”,得到了mkmf.log,结果是缺少“ ruby​​ / config.h”。然后通过“ xcode-select --install”解决了该问题。参见:

macOS Mojave 'ruby/config.h' file not found

我的机器运行的是10.13.6 macOS High Sierra。