安装“nio4r”时使用rails 5.0.0:无法构建gem原生扩展

问题描述 投票:9回答:9

这是日志:http://pastebin.com/CAgur9xd

Installing nio4r 1.2.1 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    C:/RailsInstaller/Ruby2.2.0/bin/ruby.exe -r ./siteconf20160720-8272-c88sgk.rb extconf.rb --with-cflags=-std=c99
checking for unistd.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
        --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=C:/RailsInstaller/Ruby2.2.0/bin/$(RUBY_BASE_NAME)
C:/RailsInstaller/Ruby2.2.0/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 C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:587:in `try_cpp'
         from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:1060:in `block in have_header'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:911:in `block in checking_for'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:351:in `block (2 levels) in postpone'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:321:in `open'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:351:in `block in postpone'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:321:in `open'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:347:in `postpone'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:910:in `checking_for'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:1059:in `have_header'
        from extconf.rb:3:in `<main>'

extconf failed, exit code 1

安装捆绑时,它返回(从日志中的第117行开始):

Installing nio4r 1.2.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

所以捆绑无法安装。它最后返回:

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

注意:我在其他问题中尝试了解决方案,但它仍然是相同的。如果可以手动安装“nio4r”,请告诉我如何。

ruby-on-rails ruby rubygems bundler gemfile
9个回答
7
投票

当我尝试将我的Rails升级到V5.0.0时,我遇到了同样的问题,我按照这个指令运行完美。阅读“安装Ruby DevKit”部分>> http://jekyll-windows.juthilo.com/1-ruby-and-devkit/


3
投票

Fedora 64bit的解决方案

sudo dnf install redhat-rpm-config

1
投票

我遇到了这个问题,因为我也设置了rails。 (寻找PHP的替代品)。

  • 我意识到我已经用x64 Devkit安装了x86 ruby​​,所以我首先下载了x64 ruby​​,我安装并卸载了x86版本。我确保我的路径变量设置得很好。
  • 然后我使用本页http://rubyonwindowsguides.github.io/book/ch02-04.html上的说明安装了devkit
  • 最后我安装了rails,这次工作正常,没有错误

希望这可以帮助


1
投票

我的儿子为我解决了这个问题。问题是我首先安装了Ruby,然后安装了Rails安装程序。所以我不得不卸载Ruby并仅使用Rails安装程序重新安装。


0
投票

删除Gemfile.lock并运行bundle install命令


0
投票

引用您的日志输出:

编译器无法生成可执行文件。 (RuntimeError)您必须首先安装开发工具。

在Windows上,你需要install the DevKit才能编译宝石。


0
投票

我有类似的问题,运行此命令解决了我的问题。

bundle config build.nio4r --with-cflags="-std=c99"

现在你可以成功运行bundle install了。


0
投票

在Ubuntu 16.04上有同样的问题。我做了什么来解决这个问题:

删除Gemfile.lock:sudo rm Gemfile.lock已安装的Ruby-Dev:

sudo apt-add-repository ppa:brightbox / ruby​​-ng sudo apt-get update sudo apt-get install ruby​​2.4-dev

而重要的一步:重新启动!


0
投票

如果您使用Windows并使用版本大于或等于2.4的RubyInstaller安装ruby,那么您不应该从RubyInstaller网站安装DevKit并且只使用在带RubyInstaller的Ruby之后安装的'msys64'(确保键入3号以安装两个msys和mingw)。从PATH环境变量中删除devkit目录及其路径,因此当rubygems尝试安装nio4r并调用C编译器时,它将调用msys文件。请阅读https://rubyinstaller.org/2017/05/25/rubyinstaller-2.4.1-1-released.html以获取有关RubyInstaller中MSYS2和DevKit的更多信息

© www.soinside.com 2019 - 2024. All rights reserved.