[英]How to fix a bundle “nio4r error” on Rails 5.1.6 on mac10.13
我在我的項目中使用 ruby 2.5.0、rails 5.1.6、rvm 1.29.3。
我在這篇文章中找到了一些答案How to fix a bundle install "nio4r error" on Rails 5.0.0 ,但返回相同的錯誤。
當運行 rails -v,它返回
Could not find nio4r-2.3.0 in any of the sources
Run `bundle install` to install missing gems.
然后我運行 bundle update 或 bundle ,它返回
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies........................
Using rake 12.3.1
Using concurrent-ruby 1.0.5
Using i18n 1.0.1
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.1.6
Using builder 3.2.3
Using erubi 1.7.1
Using mini_portile2 2.3.0
Using nokogiri 1.8.2
Using rails-dom-testing 2.0.3
Using crass 1.0.4
Using loofah 2.2.2
Using rails-html-sanitizer 1.0.4
Using actionview 5.1.6
Using rack 2.0.5
Using rack-test 1.0.0
Using actionpack 5.1.6
Fetching nio4r 2.3.1 (was 2.3.0)
Installing nio4r 2.3.1 (was 2.3.0) with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/apple/.rvm/gems/ruby-2.5.0/gems/nio4r-2.3.1/ext/nio4r
/Users/apple/.rvm/rubies/ruby-2.5.0/bin/ruby -r ./siteconf20180529-30171-1q1064e.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
--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/apple/.rvm/rubies/ruby-2.5.0/bin/$(RUBY_BASE_NAME)
/Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:590:in `try_cpp'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:1097:in `block in have_header'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:947:in `block in checking_for'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:350:in `block (2 levels) in postpone'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:320:in `open'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:350:in `block in postpone'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:320:in `open'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:346:in `postpone'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:946:in `checking_for'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:1096:in `have_header'
from extconf.rb:14:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/apple/.rvm/gems/ruby-2.5.0/extensions/x86_64-darwin-17/2.5.0/nio4r-2.3.1/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/apple/.rvm/gems/ruby-2.5.0/gems/nio4r-2.3.1 for inspection.
Results logged to /Users/apple/.rvm/gems/ruby-2.5.0/extensions/x86_64-darwin-17/2.5.0/nio4r-2.3.1/gem_make.out
An error occurred while installing nio4r (2.3.1), and Bundler cannot continue.
Make sure that `gem install nio4r -v '2.3.1' --source 'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
animate-rails was resolved to 1.0.10, which depends on
rails was resolved to 5.1.6, which depends on
actioncable was resolved to 5.1.6, which depends on
nio4r
運行時
gem install nio4r -v '2.3.1' --source 'https://rubygems.org/'
它返回
Building native extensions. This could take a while...
ERROR: Error installing nio4r:
ERROR: Failed to build gem native extension.
current directory: /Users/apple/.rvm/gems/ruby-2.5.0/gems/nio4r-2.3.0/ext/nio4r
/Users/apple/.rvm/rubies/ruby-2.5.0/bin/ruby -r ./siteconf20180529-30246-h59is8.rb extconf.rb
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
--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/apple/.rvm/rubies/ruby-2.5.0/bin/$(RUBY_BASE_NAME)
/Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:590:in `try_cpp'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:1097:in `block in have_header'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:947:in `block in checking_for'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:350:in `block (2 levels) in postpone'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:320:in `open'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:350:in `block in postpone'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:320:in `open'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:346:in `postpone'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:946:in `checking_for'
from /Users/apple/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/mkmf.rb:1096:in `have_header'
from extconf.rb:14:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/apple/.rvm/gems/ruby-2.5.0/extensions/x86_64-darwin-17/2.5.0/nio4r-2.3.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/apple/.rvm/gems/ruby-2.5.0/gems/nio4r-2.3.0 for inspection.
Results logged to /Users/apple/.rvm/gems/ruby-2.5.0/extensions/x86_64-darwin-17/2.5.0/nio4r-2.3.0/gem_make.out
我的 mkmf.log 是
"gcc -o conftest -I/Users/apple/.rvm/rubies/ruby-2.5.0/include/ruby-2.5.0/x86_64-darwin17 -I/Users/apple/.rvm/rubies/ruby-2.5.0/include/ruby-2.5.0/ruby/backward -I/Users/apple/.rvm/rubies/ruby-2.5.0/include/ruby-2.5.0 -I. -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl@1.1/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -std=c99 conftest.c -L. -L/Users/apple/.rvm/rubies/ruby-2.5.0/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl@1.1/lib -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl@1.1/lib -lruby.2.5.0 -lpthread -lgmp -ldl -lobjc "
In file included from conftest.c:1:
In file included from /Users/apple/.rvm/rubies/ruby-2.5.0/include/ruby-2.5.0/ruby.h:33:
In file included from /Users/apple/.rvm/rubies/ruby-2.5.0/include/ruby-2.5.0/ruby/ruby.h:29:
In file included from /Users/apple/.rvm/rubies/ruby-2.5.0/include/ruby-2.5.0/ruby/defines.h:120:
In file included from /usr/include/stdlib.h:65:
In file included from /usr/include/sys/wait.h:110:
In file included from /usr/include/sys/resource.h:72:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
/usr/local/include/stdint.h:2:10: error: #include nested too deeply
#include <stddef.h>
^
/usr/local/include/stdint.h:59:11: error: #include nested too deeply
# include <stdint.h>
^
/usr/local/include/stdint.h:72:11: error: #include nested too deeply
# include <sys/types.h>
^
/usr/local/include/stdint.h:76:10: error: #include nested too deeply
#include <limits.h>
^
/usr/local/include/stdint.h:82:11: error: #include nested too deeply
# include <inttypes.h>
^
In file included from conftest.c:1:
In file included from /Users/apple/.rvm/rubies/ruby-2.5.0/include/ruby-2.5.0/ruby.h:33:
In file included from /Users/apple/.rvm/rubies/ruby-2.5.0/include/ruby-2.5.0/ruby/ruby.h:29:
In file included from /Users/apple/.rvm/rubies/ruby-2.5.0/include/ruby-2.5.0/ruby/defines.h:120:
In file included from /usr/include/stdlib.h:65:
In file included from /usr/include/sys/wait.h:110:
/usr/include/sys/resource.h:197:2: error: unknown type name 'uint64_t'
uint64_t ri_user_time;
^
/usr/include/sys/resource.h:198:2: error: unknown type name 'uint64_t'
uint64_t ri_system_time;
^
/usr/include/sys/resource.h:199:2: error: unknown type name 'uint64_t'
uint64_t ri_pkg_idle_wkups;
^
/usr/include/sys/resource.h:200:2: error: unknown type name 'uint64_t'
/usr/include/sys/resource.h:201:2: error: unknown type name 'uint64_t'
uint64_t ri_pageins;
^
/usr/include/sys/resource.h:202:2: error: unknown type name 'uint64_t'
uint64_t ri_wired_size;
^
/usr/include/sys/resource.h:203:2: error: unknown type name 'uint64_t'
uint64_t ri_resident_size;
^
/usr/include/sys/resource.h:204:2: error: unknown type name 'uint64_t'
uint64_t ri_phys_footprint;
^
/usr/include/sys/resource.h:205:2: error: unknown type name 'uint64_t'
uint64_t ri_proc_start_abstime;
^
/usr/include/sys/resource.h:206:2: error: unknown type name 'uint64_t'
uint64_t ri_proc_exit_abstime;
^
/usr/include/sys/resource.h:211:2: error: unknown type name 'uint64_t'
uint64_t ri_user_time;
^
/usr/include/sys/resource.h:212:2: error: unknown type name 'uint64_t'
uint64_t ri_system_time;
^
/usr/include/sys/resource.h:213:2: error: unknown type name 'uint64_t'
uint64_t ri_pkg_idle_wkups;
/usr/include/sys/resource.h:214:2: error: unknown type name 'uint64_t'
uint64_t ri_interrupt_wkups;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
首先嘗試下面的配置
bundle config build.nio4r --with-cflags="-std=c99"
bundle
后
brew update
和
bundle update
找到了很多答案,大多類似於@PPL 的解決方案,但這對我不起作用。
最后通過brew upgrade
發現opensl的問題,接着是readline、nikogiri、dylib等的問題。
需要特別注意的是,出現錯誤的解決方法往往不是重新安裝錯誤信息中提到的gem,而是重新安裝與之相關的其他gem。 比如我的報錯信息出現dylib ,結果就是 dylib 依賴的節點問題。 重新安裝節點並解決它。 錯誤信息出現bindex ,但結果是 bindex 依賴的libiconv問題。 重新安裝 libiconv 即可解決問題。
最后發現上述問題是dmg安裝而不是homebrew安裝的curl和node造成的。
升級到 MAC OS BIG Sur 后面臨同樣的問題
運行以下命令:
可選的 :
brew update/brew upgrade
運行以下命令:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.