简体   繁体   English

rails 5.0.0 安装“nio4r”时:无法构建 gem 本机扩展

[英]rails 5.0.0 when installing “nio4r” : Failed to build gem native extension

Here is the logs: http://pastebin.com/CAgur9xd这是日志: 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

when installing bundle it returns(starts at line 117 in the logs ):安装包时,它返回(从日志中的第 117 行开始):

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

So the bundle can't be installed.所以无法安装该包。 It returns at the end :它在最后返回:

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.

Note :I have tried the solutions in other questions, but it is still the same.注意:我已经尝试了其他问题中的解决方案,但还是一样。 If it is possible to install "nio4r" manually please tell me how .如果可以手动安装“nio4r”,请告诉我如何安装。

I am facing the same issue while I was trying to upgrade my Rails to V5.0.0, I follow this instruction and it works perfectly.我在尝试将 Rails 升级到 V5.0.0 时遇到了同样的问题,我按照此说明进行操作,它运行良好。 Read the section "Install the Ruby DevKit" here >> http://jekyll-windows.juthilo.com/1-ruby-and-devkit/在此处阅读“安装 Ruby DevKit”部分 >> http://jekyll-windows.juthilo.com/1-ruby-and-devkit/

Fedora 64位解决方案

sudo dnf install redhat-rpm-config

I had a similar problem and running this command solved my issue.我遇到了类似的问题,运行此命令解决了我的问题。

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

Now you can successfully run bundle install afterwards.现在您可以成功运行bundle install之后。

I came across this problem as i was setting up rails too.我在设置导轨时也遇到了这个问题。 (looking for an alternative to php). (正在寻找 php 的替代品)。

  • I realized that i had installed x86 ruby with x64 Devkit, so i first downloaded x64 ruby which i installed and uninstalled the x86 version.我意识到我已经用 x64 Devkit 安装了 x86 ruby​​,所以我首先下载了 x64 ruby​​,我安装并卸载了 x86 版本。 I made sure my path variables were well set.我确保我的路径变量设置得很好。
  • Then i installed devkit using the instructions on this page http://rubyonwindowsguides.github.io/book/ch02-04.html然后我使用此页面上的说明安装了 devkit http://rubyonwindowsguides.github.io/book/ch02-04.html
  • Finally i installed rails and it worked fine without the errors this time最后我安装了 rails,这次它工作正常,没有错误

Hope this helps希望这可以帮助

My son fixed this problem for me.我儿子为我解决了这个问题。 The problem was that I installed first, Ruby and then the Rails installer.问题是我先安装了 Ruby,然后是 Rails 安装程序。 So I had to uninstall Ruby and reinstall with the Rails installer only.所以我不得不卸载 Ruby 并仅使用 Rails 安装程序重新安装。

Had this same issue on Ubuntu 16.04.在 Ubuntu 16.04 上有同样的问题。 What I did to fix this :我做了什么来解决这个问题:

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

sudo apt-add-repository ppa:brightbox/ruby-ng sudo apt-get update sudo apt-get install ruby2.4-dev sudo apt-add-repository ppa:brightbox/ruby-ng sudo apt-get 更新 sudo apt-get install ruby​​2.4-dev

and the important step : REBOOT!和重要的一步:重新启动!

this may be related: GCC compilation error when installing Nokogiri这可能与: 安装 Nokogiri 时 GCC 编译错误有关

I found a error.我发现了一个错误。 i had a 2 gcc versions installed on my system and I just run brew unlink gcc and that solved the problem.我的系统上安装了 2 个 gcc 版本,我只运行brew unlink gcc就解决了问题。

this was my case too.这也是我的情况。 benw unlink gcc worked benw unlink gcc工作

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

To quote from your log output:引用您的日志输出:

The compiler failed to generate an executable file.编译器无法生成可执行文件。 (RuntimeError) You have to install development tools first. (RuntimeError) 你必须先安装开发工具。

On windows, you need to install the DevKit in order to be able to compile gems.在 Windows 上,您需要安装 DevKit才能编译 gems。

If you use Windows and installed ruby with RubyInstaller with version more or equal to 2.4, than you should not install DevKit from RubyInstaller website and only use 'msys64' which is installed after Ruby with RubyInstaller (make sure you type number 3 to install both msys and mingw).如果您使用 Windows 并安装了 RubyInstaller 版本大于或等于 2.4 的 ruby​​,那么您不应该从 RubyInstaller 网站安装 DevKit,而只能使用在 RubyInstaller 之后安装的“msys64”(确保键入数字 3 以安装两个 msys和 mingw)。 Delete devkit directory and its path from PATH environment variable, so when rubygems will try to install nio4r and call C compilers, it will call msys ones.从PATH环境变量中删除devkit目录及其路径,所以当rubygems尝试安装nio4r并调用C编译器时,它会调用msys编译器。 Read here https://rubyinstaller.org/2017/05/25/rubyinstaller-2.4.1-1-released.html for more info about MSYS2 and DevKit in RubyInstaller在此处阅读https://rubyinstaller.org/2017/05/25/rubyinstaller-2.4.1-1-released.html了解有关 RubyInstaller 中 MSYS2 和 DevKit 的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM