我在项目中使用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 */
答案 0 :(得分:0)
首先尝试配置
bundle config build.nio4r --with-cflags="-std=c99"
bundle
在
brew update
和
bundle update
答案 1 :(得分:0)
找到了很多答案,大多数与@ PPL的解决方案类似,但这对我没有用。
最后,我发现问题通过brew upgrade
开放,然后是readline,nikogiri,dylib等问题。
需要特别注意的是,错误的解决方案通常不是重新安装错误消息中提到的gem,而是重新安装与之关联的其他gem。例如,当我的错误消息显示为 dylib 时,结果是dylib依赖的节点问题。重新安装节点并解决它。错误消息显示为 bindex ,但结果是bindex依赖的 libiconv 问题。重新安装libiconv以解决问题。
最后,发现上述问题是由dmg安装而不是自制软件安装的curl和节点造成的。
答案 2 :(得分:0)
升级到 MAC OS BIG Sur 后面临同样的问题
运行以下命令:
可选:
brew update/brew upgrade
运行以下:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install