1

I use ruby 2.5.0, rails 5.1.6, rvm 1.29.3 on my project.

I find some answer on this post How to fix a bundle install "nio4r error" on Rails 5.0.0,but return the same error.

when run rails -v, it return

Could not find nio4r-2.3.0 in any of the sources
Run `bundle install` to install missing gems.

then I run bundle update or bundle , it return

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

when run

gem install nio4r -v '2.3.1' --source 'https://rubygems.org/'

it return

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

my mkmf.log is

"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 */   
jiujiu99
  • 11
  • 1
  • 5

3 Answers3

1

try config below first

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

After

brew update 

and

bundle update
PPL
  • 6,357
  • 1
  • 11
  • 30
0

Found a lot of answers, mostly similar to @PPL's solution, but this doesn't work for me.

Finally, I found the problem opensl through brew upgrade, followed by problems with readline, nikogiri, dylib, and so on.

What needs special attention is that the solution to an error is often not to reinstall the gem mentioned in the error message, but to reinstall other gems associated with it. For example, when my error message appears dylib, the result is the node problem that dylib relies on. Reinstall the node and resolve it. The error message appears bindex, but the result is the libiconv problem that bindex depends on. Reinstall libiconv to solve the problem.

Finally, it was found that the above problems were caused by curl and node installed by dmg installation instead of homebrew.

jiujiu99
  • 11
  • 1
  • 5
0

Was facing the same issue after upgrading to MAC OS BIG Sur

Run the following commands:

Optional :

brew update/brew upgrade

Run the following :

sudo rm -rf /Library/Developer/CommandLineTools

sudo xcode-select --install
Shreehari
  • 334
  • 4
  • 10