Error installing json: Failed to build gem native extension - json

Spent some time figuring this one out this:
gem install json
Resulted in this error:
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby/bin/ruby -r ./siteconf20150611-1112-jqgxzj.rb extconf.rb
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling generator.c
linking shared-object json/ext/generator.so
/usr/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
make: *** [generator.so] Error 1
make failed, exit code 2
The important line here is "cannot find -lgmp".

Solution:
sudo apt-get install libgmp-dev

Related

Fail to install mysql2 on bundle install ruby

fail install mysql when run bundle install
i try to install rails project that use mysql2 as database, but i got this error when try to install mysql
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /opt/homebrew/Cellar/mysql/8.0.26/lib
-----
creating Makefile
current directory: /Users/<username>/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/<username>/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib/'
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/<username>/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3 for
inspection.
Results logged to
/Users/<username>/.rvm/gems/ruby-2.6.5/extensions/-darwin-20/2.6.0/mysql2-0.5.3/gem_make.out
An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'` succeeds before
bundling.
In Gemfile:
mysql2
seems like 'bundle' try to access ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib/'
meanwhil openssl path is on : opt/homebrew/opt/openssl#1.1/lib/
how to change '-L/usr/local/opt/openssl/lib/' to opt/homebrew/opt/openssl#1.1/lib/
someone can help ?
Please install the following Linux packages if you're using Linux:
sudo apt update
sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev
many RubyGems required native libraries from them.
and run bundle install again.
The same thing happens to me in Rails 6.1.4.1 (Ruby 3.0.1p64).
I have tried to executed brew info openssl, then follow display some guide.
echo 'export PATH="/usr/local/opt/openssl#1.1/bin:$PATH"' >> /Users/user/.bash_profile
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.4

Bundle Install Json Error

My ruby environment is pretty much setup. I can retrieve my Gherkins syntax via command line and run simple ruby web tests. But I need some other gems to complete the environment. All I need to do is get bundle install working, but can't figure out why it's not installing. I've updated my gems as well. I'm using Ruby 2.2.3 on Windows 10. Below is my output after trying to run.
C:\GitHubFiles\MyAccountWeb-Tests>bundle install
Fetching gem metadata from http://rubygems.org/............
Resolving dependencies...
Using public_suffix 3.0.2
Using addressable 2.5.2
Using awesome_print 1.8.0
Installing json 2.1.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
C:/Ruby22-x64/bin/ruby.exe -r ./siteconf20180817-13500-1p562oy.rb extconf.rb creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
make failed, uncaught signal 11
Gem files will remain installed in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/json-2.1.0 for inspection.
Results logged to
C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0/json-2.1.0/gem_make.out
An error occurred while installing json (2.1.0), and Bundler cannot
continue.
Make sure that `gem install json -v '2.1.0' --source 'http://rubygems.org/'`
succeeds before bundling.
In Gemfile:
appium_lib was resolved to 9.7.1, which depends on
json
My source is already set to 'http://rubygems.org/'. I ran 'gem sources -r https://rubygems.org -a http://rubygems.org' to confirm this. My output after trying to run 'gem install json -v '2.1.0' is below.
C:\GitHubFiles\MyAccountWeb-Tests>gem install json -v '2.1.0'
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
current directory: C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/json-2.1.0/ext/json/ext/generator
C:/Ruby22-x64/bin/ruby.exe -r ./siteconf20180817-15312-13stnps.rb extconf.rb
creating Makefile
current directory: C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/json-2.1.0/ext/json/ext/generator
make "DESTDIR=" clean
current directory: C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/json-2.1.0/ext/json/ext/generator
make "DESTDIR="
make failed, uncaught signal 11
Gem files will remain installed in C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/json-2.1.0 for inspection.
Results logged to C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0/json-2.1.0/gem_make.out
gem_make text file
current directory: C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/json-2.1.0/ext/json/ext/generator
C:/Ruby22-x64/bin/ruby.exe -r ./siteconf20180817-10044-ypvx4a.rb extconf.rb
creating Makefile
current directory: C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/json-2.1.0/ext/json/ext/generator
make "DESTDIR=" clean
current directory: C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/json-2.1.0/ext/json/ext/generator
make "DESTDIR="
make failed, uncaught signal 11
According to this link, I should try rake install. https://www.rubydoc.info/gems/json/2.1.0. But it just says rake aborted. No rake file found.
I also tried 'gem install bundler -v '= 1.5.1'' followed by 'bundle package', which created the same json error.
I've tried bundle update and bundle update json.
I read that there was a problem with json version 1.8.1 and ruby 2.2.3, so install json 1.8.3 version, so I tried gem install json -v1.8.3. Same json error.
I tried deleting my gemfile and running bundle update again, which replaced the gemfile and created the bundle install error again :(
I am stuck!

Install mysql2 gem on macOS Sierra

I'm trying to install mysql2 gem (0.4.5) on macOS Sierra (10.12.1) and getting the error. I don't have local mysql server, it's remote.
Here is error log:
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mysql-connector-c/6.1.9/lib
-----
creating Makefile
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.4.4/mkmf.log
current directory: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/mysql2-0.4.4/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/mysql2-0.4.4/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -l-lpthread
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
Did anyone meet similar error?
Fix:
Edit /usr/local/Cellar/mysql-connector-c/6.1.10/bin/mysql_config, find this line:
libs="$libs -l "
and change it to
libs="$libs -l mysqlclient "
Explanation:
-l-lpthread
The linker does not understand the option -l-lpthread. Two -l-l linker options are jammed up against each other. It is because the library name mysqlclientis missing from the generated make file.
I ran into this issue when trying to build the native extensions for the mysql2 gem on Ruby 2.4.1 using the mysql-connector-c from Home Brew
This was on MacOS 10.12.5.
The generated LIBS variable should look something this:
LIBS = $(LIBRUBYARG_SHARED) -L/usr/local/Cellar/mysql-connector-c/6.1.10/lib -l mysqlclient -lpthread -ldl -lobjc
It appears the variable is expanded from the file /usr/local/Cellar/mysql-connector-c/6.1.10/bin/mysql_config
The libs var in the file mysql_config should contain:
libs="$libs -l mysqlclient "
instead of
libs="$libs -l "
The var embedded_libs may be wrong too?
The mysql-connector-c lib installs and build fine via Home Brew it just appears the file mysql_config is incorrect or generated incorrectly.
Not sure the cause of the issue. Possibly Home Brew, mysql-connector-c, mysql2 gem build process, user environment?
The issue is that you're missing a library as the error message indicates
ld: library not found for -l-lpthread
EDIT:
There seem to be other errors related that may be fixed with the instructions below, namely:
ld: library not found for -lssl
My guess is that you did not install xcode yet which happens to install a few more libraries. Please make sure to install xcode through the official app-store.
It might be necessary to re-install the command-line tools again as well (even if you had xcode installed and just updated it at some point).
xcode-select --install
Let me know if this helped!
I'm not sure if the issue is that the mysql-connector-c formula is broken in Homebrew, or if the issues lies in the mysql2 gem, but you can work around the issue by installing the mysql formula.
Even if you don't need a local MySQL server for development, the version of mysql_config from the mysql formula correctly returns the list of libraries required to link the gem's native extension.
If you already have mysql-connector-c installed:
brew unlink mysql-connector-c
# OR
brew uninstall mysql-connector-c
Install the mysql formula:
brew install mysql

MySQL Gem Install Error on Ruby 2.4

I have a problem with an install of mysql gem. This is my error :
gem install mysql -v '2.9.1'
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
current directory: /usr/local/rvm/gems/ruby-2.4.0/gems/mysql-2.9.1/ext/mysql_api
/usr/local/rvm/rubies/ruby-2.4.0/bin/ruby -r ./siteconf20170107-4120-x2dv85.rb extconf.rb
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... yes
checking for rb_thread_start_timer()... no
checking for mysql.h... yes
creating Makefile
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/usr/local/rvm/gems/ruby-2.4.0/extensions/x86_64-linux/2.4.0/mysql-2.9.1/mkmf.log
current directory: /usr/local/rvm/gems/ruby-2.4.0/gems/mysql-2.9.1/ext/mysql_api
make "DESTDIR=" clean
current directory: /usr/local/rvm/gems/ruby-2.4.0/gems/mysql-2.9.1/ext/mysql_api
make "DESTDIR="
compiling mysql.c
mysql.c: In function ‘stmt_bind_result’:
mysql.c:1320:74: error: ‘rb_cFixnum’ undeclared (first use in this function)
else if (argv[i] == rb_cNumeric || argv[i] == rb_cInteger || argv[i] == rb_cFixnum)
^
mysql.c:1320:74: note: each undeclared identifier is reported only once for each function it appears in
mysql.c: At top level:
cc1: warning: unrecognized command line option "-Wno-self-assign"
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand"
cc1: warning: unrecognized command line option "-Wno-parentheses-equality"
cc1: warning: unrecognized command line option "-Wno-tautological-compare"
Makefile:241: recipe for target 'mysql.o' failed
make: *** [mysql.o] Error 1
make failed, exit code 2
Gem files will remain installed in /usr/local/rvm/gems/ruby-2.4.0/gems/mysql-2.9.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.4.0/extensions/x86_64-linux/2.4.0/mysql-2.9.1/gem_make.out
When i try this command sudo gem install mysql -v '2.9.1', it's works, and I read this line to justify it...
sudo gem install mysql -v '2.9.1'
Building native extensions. This could take a while...
Successfully installed mysql-2.9.1
Parsing documentation for mysql-2.9.1
Done installing documentation for mysql after 0 seconds
1 gem installed
I don't understand what happened and how to solved this. If someone could help me...
The mysql gem is one of many gems which doesn't like the unification of the integer types in Ruby 2.4.
Unfortunately, since the mysql gem isn't really maintained anymore, I wouldn't hold my breath for an updated version. As a workaround, you can switch to a Ruby version before 2.4, e.g. Ruby 2.3.3.
Alternatively, you could switch to the mysql2 gem which is actively maintained, has a similar API to the mysql gem and in its latest version is compatible with Ruby 2.4.

An error occurred while installing json (1.8.1), and Bundler cannot continue

I am trying to upgrade the redmine. In order to create the session variable, after following several steps I have to run the bundle install to make sure all the gems are instaalled
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension
C:/PROGRA~1/BITNAM~1/ruby/bin/ruby.exe extconf.rb
creating Makefile
make
gcc -I. -I/C/PROGRA~1/BITNAM~1/ruby/lib/ruby/1.8/i386-mingw32 -I/C/PROGRA~1/BITN
AM~1/ruby/lib/ruby/1.8/i386-mingw32 -I. -DJSON_GENERATOR -g -O3 -DFD_SETSIZE=
256 -Wall -O0 -ggdb -c generator.c
/bin/sh: /usr/mingw/bin/gcc: Bad file number
make: *** [generator.o] Error 126
enter code here
Gem files will remain installed in C:/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/g
ems/json-1.8.1 for inspection.
Results logged to C:/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/json-1.8.1/ex
t/json/ext/generator/gem_make.out
An error occurred while installing json (1.8.1), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.1'` succeeds before bundling.
I am not able run the command bundle install in ruby
bundle update json
Did not work for me,
Instead i did run following command.
bundle update
and then
bundle install
I am running a Kali, was trying to install SNORBY after successful installation of SNORT, PULLED PORK and BARNYARD2.
Above solution fixed the problem
Try locking JSON gem to 1.8.0 in your gemfile and doing an update
gem 'json', '1.8.0'
then run
bundle update json