3

I am beginner and I can't understand how to fix my error when I try to install Bundle. I'm following the Schneems lessons(currently doing routes_controller_exercise).

Here's my error :

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

/Users/admin/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151101-96612-c518oi.rb extconf.rb
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:158:47: error: too few arguments provided to function-like macro invocation
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
                                          ^
/Users/admin/.rbenv/versions/2.2.3/include/ruby-2.2.0/ruby/intern.h:793:9: note: macro 'rb_str_new' defined here
#define rb_str_new(str, len) __extension__ (    \
    ^
In file included from generator.c:1:
./../fbuffer/fbuffer.h:158:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' [-Wint-conversion]
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
      ^        ~~~~~~~~~~
generator.c:867:22: warning: '&&' within '||' [-Wlogical-op-parentheses]
return *p == '[' && *q == ']' || *p == '{' && *q == '}';
       ~~~~~~~~~~^~~~~~~~~~~~ ~~
generator.c:867:22: note: place parentheses around the '&&' expression to silence this warning
return *p == '[' && *q == ']' || *p == '{' && *q == '}';
                 ^
       (                     )
generator.c:867:48: warning: '&&' within '||' [-Wlogical-op-parentheses]
return *p == '[' && *q == ']' || *p == '{' && *q == '}';
                              ~~ ~~~~~~~~~~^~~~~~~~~~~~
generator.c:867:48: note: place parentheses around the '&&' expression to silence this warning
return *p == '[' && *q == ']' || *p == '{' && *q == '}';
                                           ^
                                 (                     )
3 warnings and 1 error generated.
make: *** [generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/admin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/json-1.7.3 for inspection.
Results logged to /Users/admin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/json-1.7.3/gem_make.out
An error occurred while installing json (1.7.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.3'` succeeds before bundling.

I have no idea what to do. I'm a beginner so...be nice with me please ! I've been trying many solutions online, but nothing worked so far! I'm using El Capitan 10.11.1.

I've set up Ruby with this link : http://guides.railsgirls.com/install/#virtual-machine.

Doing this exercise now : https://github.com/schneems/routes_controller_exercise


Update:

So I did :

bundle update json 

and it worked until :

Installing eventmachine 0.12.10 with native extensions

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

/Users/admin/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151101-99125-1vfqvuu.rb extconf.rb
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... no
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... yes
checking for rb_thread_check_ints()... yes
checking for rb_time_new()... yes
checking for sys/event.h... yes
checking for sys/queue.h... yes
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling binder.cpp
In file included from binder.cpp:20:
./project.h:103:10: fatal error: 'openssl/ssl.h' file not found
#include <openssl/ssl.h>
     ^
1 error generated.
make: *** [binder.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/admin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-0.12.10 for inspection.
Results logged to /Users/admin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/eventmachine-0.12.10/gem_make.out
An error occurred while installing eventmachine (0.12.10), and Bundler cannot continue.
Make sure that `gem install eventmachine -v '0.12.10'` succeeds before bundling.
ip-10-0-66-6:routes_controller_exercise Admin$ gem install eventmachine -v '0.12.10'
Building native extensions.  This could take a while...
ERROR:  Error installing eventmachine:
ERROR: Failed to build gem native extension.

Solution

Ok so I've uninstall rails and re-install it with the Stanford website.

And now everything's work perfectly! I have no idea what was the problem, but now I install Bundle with no issues.

Community
  • 1
  • 1
imagirl92
  • 43
  • 1
  • 5
  • 1
    It seems the problem isn't with the json gem, but eventmachine. There is already a good solution for installing eventmachine on El Capitan: https://stackoverflow.com/questions/30818391/gem-eventmachine-fatal-error-openssl-ssl-h-file-not-found – eToThePiIPower Nov 01 '15 at 17:10
  • Thanks, I tried every solutions but I go from json error to eventmachine error. I'm going to reinstall everything. – imagirl92 Nov 01 '15 at 22:09

3 Answers3

3

One part of the problem is due to a change in rb_str_new.

This is a related issue on their GitHub page: https://github.com/flori/json/issues/229

As I understand it, the contributors decided to not fix this since it works as it should in json 1.8.3. It's recommended that you upgrade to that version. The json gem has a very stable API so backwards compatibility is usually not an issue.

If you are using bundler you should go to your Gemfile and change version of json to 1.8.3 or higher using gem 'json', '>=1.8.3'.

aross
  • 5,620
  • 1
  • 25
  • 32
  • Thanks for the answer! But I'm not sure how to edit my **Gemfile**. I only have to open the **Gemfile** in my editor and add : _gem 'json', '>=1.8.3'_ and save it ? Then I run **bundle install** on my terminal? In my project directory, I have **Gemfile** and **Gemfile.lock** . In **Gemfile**, I don't see **json** but I do in **Gemfile.lock** ( ** json (1.7.3)** ). I'm new with Ruby so I apologize for the very basic questions. – imagirl92 Nov 01 '15 at 12:06
  • I've just added an update of my situation. I think I'm going to cry, I'm so confused. – imagirl92 Nov 01 '15 at 14:03
  • @imagirl92 just adding it to your Gemfile as you explained sounds about right. It's a great answer for eventmachine here https://stackoverflow.com/questions/30818391/gem-eventmachine-fatal-error-openssl-ssl-h-file-not-found If you installed openssl using homebrew (`brew install openssl`), you should be fine just executing `bundle config build.eventmachine --with-cppflags=-I$(brew --prefix openssl)/include` and then `bundle install` again. – aross Nov 01 '15 at 17:29
  • If `bundle update json` does not work and if you do not rely on any specific version of a gem that is not specified in your `Gemfile` you can delete `Gemfile.lock` and run `bundle install` again. Then bundler will search for the best available versions for all gems that match the versions defined in `Gemfile`. – aross Nov 01 '15 at 21:54
  • I think it worked @aross ! Thank you. Just to make sure, I have this message at the end (my Ruby version : ruby 2.2.3p173 ) : `Post-install message from rdoc: Depending on your version of ruby, you may need to install ruby rdoc/ri data: <= 1.8.6 : unsupported = 1.8.7 : gem install rdoc-data; rdoc-data --install = 1.9.1 : gem install rdoc-data; rdoc-data --install >= 1.9.2 : nothing to do! Yay!` – imagirl92 Nov 02 '15 at 00:10
  • @imagirl92 great, you can just ignore that message if you will. Please consider mark my answer as the correct one if you this was the right solution :) – aross Nov 02 '15 at 16:57
0

Add gem 'json', '>=1.7.5' and remove Gemfile.lock

then run:

bundle install
-1

In Gemfile you add

gem 'json', '1.7.3'

after that,

bundle install

Kien Nguyen
  • 35
  • 2
  • 6
  • This will not change anything since the version 1.7.3 is already the version bundler tries to install according to the error message. Using `gem install json -v '1.7.3'` may instead give you additional information to solve the issue or allows you to add additional options to like `--with-opt-dir=[dir]` (`bundle config` can also be used for this). – aross Nov 01 '15 at 11:24