Error installing gem bson_ext version 1.5.1 - ruby-on-rails

I am trying to set up a ruby 2.3.0 project in my system . Upon running bundle install , I am getting the following error :-
Fetching bson_ext 1.5.1
Installing bson_ext 1.5.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/admin/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bson_ext-1.5.1/ext/cbson
/Users/admin/.rbenv/versions/2.3.0/bin/ruby -I /Users/admin/.rbenv/versions/2.3.0/lib/ruby/site_ruby/2.3.0 -r ./siteconf20201009-77301-z7iyto.rb
extconf.rb
checking for asprintf()... yes
checking for ruby/st.h... yes
checking for ruby/regex.h... yes
checking for ruby/encoding.h... yes
creating Makefile
current directory: /Users/admin/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bson_ext-1.5.1/ext/cbson
make "DESTDIR=" clean
current directory: /Users/admin/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bson_ext-1.5.1/ext/cbson
make "DESTDIR="
compiling encoding_helpers.c
compiling cbson.c
cbson.c:118:36: warning: passing 'char *' to parameter of type 'const unsigned char *' converts between pointers to integer types with different sign [-Wpointer-sign]
result_t status = check_string(RSTRING_PTR(string), RSTRING_LEN(string),
^~~~~~~~~~~~~~~~~~~
/Users/admin/.rbenv/versions/2.3.0/include/ruby-2.3.0/ruby/ruby.h:994:5: note: expanded from macro 'RSTRING_PTR'
(!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./encoding_helpers.h:26:44: note: passing argument to parameter 'string' here
result_t check_string(const unsigned char* string, const int length,
^
cbson.c:602:18: error: implicit declaration of function 'bson_buffer_get_max_size' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (length > bson_buffer_get_max_size(buffer)) {
^
cbson.c:602:18: note: did you mean 'bson_buffer_set_max_size'?
./bson_buffer.h:34:6: note: 'bson_buffer_set_max_size' declared here
void bson_buffer_set_max_size(bson_buffer_t buffer, int max_size);
^
1 warning and 1 error generated.
make: *** [cbson.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/admin/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bson_ext-1.5.1 for inspection.
Results logged to /Users/admin/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-18/2.3.0-static/bson_ext-1.5.1/gem_make.out
An error occurred while installing bson_ext (1.5.1), and Bundler cannot continue.
Make sure that `gem install bson_ext -v '1.5.1'` succeeds before bundling.
In Gemfile:
bson_ext
Changing the bson_ext version does not work . I specifically need version 1.5.1 for the project.
Please help !!!

Related

Issue with Puma when installing Rails on a Mac

I'm trying to install Rails on my new machine, and I keep getting this error when bundling.
An error occurred while installing puma (4.3.5), and Bundler cannot
continue.
Make sure that `gem install puma -v '4.3.5' --source 'https://rubygems.org/'`
succeeds before bundling.
In Gemfile:
puma
When I run gem install puma -v '4.3.5' --source 'https://rubygems.org/, I get this error:
Building native extensions. This could take a while...
ERROR: Error installing puma:
ERROR: Failed to build gem native extension.
current directory: /Users/christopherdavis/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.5/ext/puma_http11
/Users/christopherdavis/.rbenv/versions/2.7.1/bin/ruby -I /Users/christopherdavis/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0 -r ./siteconf20200829-23175-2h0q0u.rb extconf.rb
checking for BIO_read() in -lcrypto... yes
checking for SSL_CTX_new() in -lssl... yes
checking for openssl/bio.h... yes
checking for DTLS_method() in openssl/ssl.h... yes
checking for TLS_server_method() in openssl/ssl.h... yes
checking for SSL_CTX_set_min_proto_version in openssl/ssl.h... yes
creating Makefile
current directory: /Users/christopherdavis/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.5/ext/puma_http11
make "DESTDIR=" clean
current directory: /Users/christopherdavis/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.5/ext/puma_http11
make "DESTDIR="
compiling http11_parser.c
ext/puma_http11/http11_parser.c:44:18: warning: unused variable 'puma_parser_en_main' [-Wunused-const-variable]
static const int puma_parser_en_main = 1;
^
1 warning generated.
compiling io_buffer.c
compiling mini_ssl.c
mini_ssl.c:145:7: warning: unused variable 'min' [-Wunused-variable]
int min, ssl_options;
^
mini_ssl.c:299:40: warning: function 'raise_error' could be declared with attribute 'noreturn' [-Wmissing-noreturn]
void raise_error(SSL* ssl, int result) {
^
2 warnings generated.
compiling puma_http11.c
puma_http11.c:203:22: error: implicitly declaring library function 'isspace' with type 'int (int)' [-Werror,-Wimplicit-function-declaration]
while (vlen > 0 && isspace(value[vlen - 1])) vlen--;
^
puma_http11.c:203:22: note: include the header <ctype.h> or explicitly provide a declaration for 'isspace'
1 error generated.
make: *** [puma_http11.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/christopherdavis/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.5 for inspection.
Results logged to /Users/christopherdavis/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-20/2.7.0/puma-4.3.5/gem_make.out
Has anyone seen this before? How might I fix the issue? I'm new to Rails and unsure of what's going on. I followed the tutorial on GoRails and found myself here.
Thanks!
See https://github.com/puma/puma/pull/2314
Run this line...
bundle config build.puma --with-cflags="-Wno-error=implicit-function-declaration"

Error installing json Ruby gem

I'm running gem install json -v '1.8.1' however I get this error..
gem install json -v '1.8.1'
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
current directory: /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1/ext/json/ext/generator
/Users/johnwilliamson/.rvm/rubies/ruby-2.4.1/bin/ruby -r ./siteconf20170412-72871-wada1h.rb extconf.rb
creating Makefile
current directory: /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1/ext/json/ext/generator
make "DESTDIR=" clean
current directory: /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:47: error: too few arguments provided to function-like macro invocation
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^
/Users/johnwilliamson/.rvm/rubies/ruby-2.4.1/include/ruby-2.4.0/ruby/intern.h:795:9: note: macro 'rb_str_new' defined here
#define rb_str_new(str, len) RB_GNUC_EXTENSION_BLOCK( \
^
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' (aka 'unsigned long (const char *, long)') [-Wint-conversion]
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^ ~~~~~~~~~~
generator.c:840:25: error: use of undeclared identifier 'rb_cFixnum'
} else if (klass == rb_cFixnum) {
^
generator.c:842:25: error: use of undeclared identifier 'rb_cBignum'
} else if (klass == rb_cBignum) {
^
1 warning and 3 errors generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1 for inspection.
Results logged to /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/extensions/x86_64-darwin-16/2.4.0/json-1.8.1/gem_make.out
When I run just gem install json it installs fine taking me over version 2 however I'm trying to install this https://github.com/peatio/peatio and it wants that version specifically.
Any other ideas?
Finding and updating the gem that is pulling in the JSON gem should work. However, another thing that worked for me was to update the version of JSON being installed.
bundle update json
This worked because it updated JSON to version 1.8.6 which is compatible with newer Rubies.
This seems to be a common issue with the json 1.8.1 gem. You can use a different version of json if you are declaring it explicitly, but in some cases, json 1.8.1 is a cascading dependency. For instance, you may see something like
In Gemfile:
rails was resolved to 4.1.5, which depends on
actionmailer was resolved to 4.1.5, which depends on
actionpack was resolved to 4.1.5, which depends on
actionview was resolved to 4.1.5, which depends on
activesupport was resolved to 4.1.5, which depends on
json
In this case, you just need to change the top level gem (in this case rails) to a different version. 4.2.6 works.
The issue is arise due to you are not in proper directory. Please go to your rails directory folder first then run this command like this:
rails#rails:~/rails_project/btc$ gem install json -v '1.8.1'
Then its work fine.

How do I build "gem install json"?

I’m using Rails 4.2.7. I’m trying to build this tutorial — https://github.com/webguyian/bookstore, but getting a strange error, “An error occurred while installing json (1.8.0), and Bundler cannot continue.” So I tried “gem install json -v '1.8.0'”
localhost:bookstore-master davea$ gem install json -v '1.8.0'
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
current directory: /Users/davea/.rvm/gems/ruby-2.3.0/gems/json-1.8.0/ext/json/ext/generator
/Users/davea/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20161007-50119-1huurrz.rb extconf.rb
creating Makefile
current directory: /Users/davea/.rvm/gems/ruby-2.3.0/gems/json-1.8.0/ext/json/ext/generator
make "DESTDIR=" clean
current directory: /Users/davea/.rvm/gems/ruby-2.3.0/gems/json-1.8.0/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:47: error: too few arguments provided to function-like macro invocation
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^
/Users/davea/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/intern.h:797: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:175:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' (aka 'unsigned long (const char *, long)') [-Wint-conversion]
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^ ~~~~~~~~~~
1 warning and 1 error generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/davea/.rvm/gems/ruby-2.3.0/gems/json-1.8.0 for inspection.
Results logged to /Users/davea/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-14/2.3.0/json-1.8.0/gem_make.out
I don’t know what this means or how to correct it. Any ideas?
The version of the json gem you are using is not compatible with Ruby >= 2.2. Please use at least version 1.8.2 of the json gem with Ruby 2.3.
See the Changelog for details about changes in functionality and compatibility.
That said, most of the time you don't even need an external gem to be able to work with JSON data in Ruby. The JSON module shipped with Ruby's standard library is fully functional and compatible with Rails already.

Could not find json-1.8.1 in any of the sources

I'm doing a project using react-rails but when I run
bundle install
I get
Could not find json-1.8.1 in any of the sources
Specifically, this is the entire error
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/montana/.rvm/gems/ruby-2.3.0/gems/json-1.8.1/ext/json/ext/generator
/Users/montana/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160629-5602-i1di2t.rb extconf.rb
creating Makefile
current directory: /Users/montana/.rvm/gems/ruby-2.3.0/gems/json-1.8.1/ext/json/ext/generator
make "DESTDIR=" clean
current directory: /Users/montana/.rvm/gems/ruby-2.3.0/gems/json-1.8.1/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:47: error: too few arguments provided to function-like macro invocation
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^
/Users/montana/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/intern.h:797: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:175:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' (aka 'unsigned long (const char *, long)') [-Wint-conversion]
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^ ~~~~~~~~~~
1 warning and 1 error generated.
make: *** [generator.o] Error 1
There's been various posts about this on stackoverflow, and have tried most "solutions' but none seem to work for me, I also ran
gem list | grep json
It says I have the json gem via
json (1.8.3)
multi_json (1.10.1)
I've tried to stop spring, updating the gems, & bundler. I've also ran
rbenv rehash
To no avail, still getting this error, any input would be highly appreciated.
I had a problem last time on Ubuntu, i tried to install this library and it worked as well.
sudo apt-get install libgmp3-dev
You can refer document at: Failed to build gem json native extension
You may want to lower down your ruby version or bump json version up. See: https://github.com/flori/json/issues/229
Had a quick look at json 1.8.1 gemspec and no mention of ruby 2.3.0 support as of today.

Can't install Puma gem on OSX 10.11.3

I just reformat my MacBook and I try to clone of my Rails project. When I do bundle install, Puma gem failed.
When I run gem install puma -v '2.13.4', I get this error:
Fetching: puma-2.13.4.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing puma:
ERROR: Failed to build gem native extension.
/Users/zulhilmi/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20160211-95547-1pdaoaq.rb extconf.rb
checking for BIO_read() in -lcrypto... yes
checking for SSL_CTX_new() in -lssl... yes
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling http11_parser.c
compiling io_buffer.c
io_buffer.c:119:10: warning: passing 'uint8_t *' (aka 'unsigned char *') to parameter of type 'const char *' converts between pointers to integer types with different sign [-Wpointer-sign]
return rb_str_new(b->top, b->cur - b->top);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/zulhilmi/.rvm/rubies/ruby-2.2.0/include/ruby-2.2.0/ruby/intern.h:796:20: note: expanded from macro 'rb_str_new'
rb_str_new_static((str), (len)) : \
^~~~~
/Users/zulhilmi/.rvm/rubies/ruby-2.2.0/include/ruby-2.2.0/ruby/intern.h:727:37: note: passing argument to parameter here
VALUE rb_str_new_static(const char *, long);
^
io_buffer.c:119:10: warning: passing 'uint8_t *' (aka 'unsigned char *') to parameter of type 'const char *' converts between pointers to integer types with different sign [-Wpointer-sign]
return rb_str_new(b->top, b->cur - b->top);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/zulhilmi/.rvm/rubies/ruby-2.2.0/include/ruby-2.2.0/ruby/intern.h:797:13: note: expanded from macro 'rb_str_new'
rb_str_new((str), (len)); \
^~~~~
/Users/zulhilmi/.rvm/rubies/ruby-2.2.0/include/ruby-2.2.0/ruby/intern.h:706:29: note: passing argument to parameter here
VALUE rb_str_new(const char*, long);
^
2 warnings generated.
compiling mini_ssl.c
In file included from mini_ssl.c:3:
/Users/zulhilmi/.rvm/rubies/ruby-2.2.0/include/ruby-2.2.0/ruby/backward/rubyio.h:2:2: warning: use "ruby/io.h" instead of "rubyio.h" [-W#warnings]
#warning use "ruby/io.h" instead of "rubyio.h"
^
mini_ssl.c:4:10: fatal error: 'openssl/bio.h' file not found
#include <openssl/bio.h>
^
1 warning and 1 error generated.
make: *** [mini_ssl.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/zulhilmi/.rvm/rubies/ruby-2.2.0/lib/ruby/gems/2.2.0/gems/puma-2.13.4 for inspection.
What should I do?
About my project and my environment:
Ruby: 2.2.0 (I'm using RVM)
Rails: 4.2.0
OSX: 10.11.3
Instead of force linking openssl(which is NOT recommended according to this Github Opened issue) as proposed by Zulhilmi Zainudin,
I recommend the following solution based on issue 783 of Puma source code(reference below).
I'm using El Capitan (10.11) with openssl installed via Homebrew:
$ gem install puma -v 2.13.4 -- --with-opt-dir=/usr/local/opt/openssl
Reference: https://github.com/puma/puma/issues/783
But if you want to make it work for all your Gemfiles you can still:
$ bundle config build.puma --with-opt-dir=/usr/local/opt/openssl
and confirm:
$ grep PUMA ~/.bundle/config
the output should be:
BUNDLE_BUILD__PUMA: "--with-opt-dir=/usr/local/opt/openssl"
Reference: https://github.com/puma/puma/issues/718
This solution works for me:
brew install openssl
brew link --force openssl

Resources