Failure to install old mysql2 gem - ruby-on-rails

I am using Mac High Sierra. I am using Ruby 2.2.1 with RVM. I need to use mysql2 with this Ruby on Rails app. I do have mysql 5.7 installed. I do have xcode installed along with the command-line tools.
I am simply trying to get this company app working on my local machine. I know that I am very close but I have one final error when I do bundle install I receive the following error when I get to the mysql2 gem:
Fetching mysql2 0.3.18
Installing mysql2 0.3.18 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/ahayden/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.18/ext/mysql2
/Users/ahayden/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20180710-52515-2hjll8.rb extconf.rb
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.11/lib
-----
creating Makefile
current directory: /Users/ahayden/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.18/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/ahayden/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.18/ext/mysql2
make "DESTDIR="
compiling infile.c
compiling client.c
client.c:359:33: warning: implicit conversion loses integer precision: 'long' to 'unsigned int' [-Wshorten-64-to-32]
elapsed_time = end_time - start_time;
~ ~~~~~~~~~^~~~~~~~~~~~
client.c:1163:56: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'unsigned int' [-Wshorten-64-to-32]
mysql2rb = mysql2_mysql_enc_name_to_rb(charset_name, charset_name_len);
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~
2 warnings generated.
compiling mysql2_ext.c
compiling result.c
result.c:186:17: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
for (i = 0; i < (len - 1); i++) {
~ ^ ~~~~~~~
1 warning generated.
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
Gem files will remain installed in /Users/ahayden/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.18 for inspection.
Results logged to /Users/ahayden/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-17/2.2.0/mysql2-0.3.18/gem_make.out
An error occurred while installing mysql2 (0.3.18), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.18'` succeeds before bundling.
In Gemfile:
mysql2
I've tried just installing mysql2 without the specific gem version and it works, but it did not fix my problem. It seems to boil down to the bottom of the traceback where it cannot find library -l-lpthread. Please help, I've been trying to do this all day.

This fixed it for me
gem install mysql2 -v '0.3.21' -- --with-cflags=\"-I/usr/local/opt/openssl/include\" --with-ldflags=\"-L/usr/local/opt/openssl/lib\"
after installing openssl
brew install openssl

As per the description shared it seems like the mysql dependencies are unable to install.
First we need to ‘locate mysql_config’ and then replace the path in the following command with where that file is.
gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Related

Semian gem Gem::Ext::BuildError: ERROR on Ubuntu 20.04

Fresh Ubuntu 20.04 install, when I try to bundle my project, I get this error which I'm not sure what's producing it.
Installing semian 0.10.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /home/fran/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/semian-0.10.0/ext/semian
/home/fran/.rbenv/versions/2.4.3/bin/ruby -r ./siteconf20200922-5726-1n8pgk.rb extconf.rb --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
checking for openssl/sha.h... yes
checking for SHA1() in -lcrypto... yes
checking for sys/ipc.h... yes
checking for sys/sem.h... yes
checking for sys/types.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_without_gvl()... yes
creating Makefile
current directory: /home/fran/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/semian-0.10.0/ext/semian
make "DESTDIR=" clean
current directory: /home/fran/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/semian-0.10.0/ext/semian
make "DESTDIR="
compiling resource.c
In file included from /home/fran/.rbenv/versions/2.4.3/include/ruby-2.4.0/ruby.h:33,
from sysv_semaphores.h:15,
from resource.h:10,
from resource.c:1:
/home/fran/.rbenv/versions/2.4.3/include/ruby-2.4.0/ruby/ruby.h:631:1: error: ‘const’ attribute on function returning ‘void’ [-Werror=attributes]
631 | CONSTFUNC(void rb_secure_update(VALUE));
| ^~~~~~~~~
In file included from /home/fran/.rbenv/versions/2.4.3/include/ruby-2.4.0/ruby/ruby.h:2008,
from /home/fran/.rbenv/versions/2.4.3/include/ruby-2.4.0/ruby.h:33,
from sysv_semaphores.h:15,
from resource.h:10,
from resource.c:1:
/home/fran/.rbenv/versions/2.4.3/include/ruby-2.4.0/ruby/intern.h:257:1: error: ‘const’ attribute on function returning ‘void’ [-Werror=attributes]
257 | CONSTFUNC(void rb_error_untrusted(VALUE));
| ^~~~~~~~~
/home/fran/.rbenv/versions/2.4.3/include/ruby-2.4.0/ruby/intern.h:259:1: error: ‘const’ attribute on function returning ‘void’ [-Werror=attributes]
259 | CONSTFUNC(void rb_check_trusted(VALUE));
| ^~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:242: resource.o] Error 1
make failed, exit code 2
Gem files will remain installed in /home/fran/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/semian-0.10.0 for inspection.
Results logged to /home/fran/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0/semian-0.10.0/gem_make.out
An error occurred while installing semian (0.10.0), and Bundler cannot continue.
Make sure that `gem install semian -v '0.10.0' --source 'https://rubygems.org/'` succeeds before bundling.
Did not have this problem bundling other projects that require native extensions, just this one where we make use of the semian gem.

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"

Cannot install sqlite3 gem

I am trying to run the bundle command to install all the gems for a todo application. All gems have downloaded without a problem but the sqlite3 gem has not. I have no idea what the following means could somebody please explain what is going on and how to fix?
Installing sqlite3 1.3.8 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/Users/tomfinet/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151208-
2023-1esrcfp.rb extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for sqlite3_initialize()... yes
checking for sqlite3_backup_init()... yes
checking for sqlite3_column_database_name()... no
checking for sqlite3_enable_load_extension()... no
checking for sqlite3_load_extension()... no
checking for sqlite3_open_v2()... yes
checking for sqlite3_prepare_v2()... yes
checking for sqlite3_int64 in sqlite3.h... yes
checking for sqlite3_uint64 in sqlite3.h... yes
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling backup.c
compiling database.c
compiling exception.c
compiling sqlite3.c
compiling statement.c
statement.c:261:11: warning: implicit declaration of function 'RBIGNUM' is invalid in C99 [-Wimplicit-function-declaration]
if (RBIGNUM_LEN(value) * SIZEOF_BDIGITS <= 8) {
^
./sqlite3_ruby.h:16:24: note: expanded from macro 'RBIGNUM_LEN'
#define RBIGNUM_LEN(x) RBIGNUM(x)->len
^
statement.c:261:11: error: member reference type 'int' is not a pointer
if (RBIGNUM_LEN(value) * SIZEOF_BDIGITS <= 8) {
^~~~~~~~~~~~~~~~~~
./sqlite3_ruby.h:16:36: note: expanded from macro 'RBIGNUM_LEN'
#define RBIGNUM_LEN(x) RBIGNUM(x)->len
~~~~~~~~~~ ^
statement.c:261:32: error: use of undeclared identifier 'SIZEOF_BDIGITS'
if (RBIGNUM_LEN(value) * SIZEOF_BDIGITS <= 8) {
^
1 warning and 2 errors generated.
make: *** [statement.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.8 for inspection.
Results logged to /Users/tomfinet/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/sqlite3-1.3.8/gem_make.out
An error occurred while installing sqlite3 (1.3.8), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.8'` succeeds before bundling.
What is the problem and how do I fix it?
Thanks.
bundle update sqlite3
Have a look at this gist
Ah, looks like it’s an issue with the sqlite3 v1.4.0 gem which was released on February 4.
Mention the following sqlite3 version in your gem file:
gem "sqlite3", "~> 1.3.6”
Then make sure to “bundle install”.
You need the SQLite3 development headers for the gem’s native extension to compile against. You can install them by running (possibly with sudo):
apt-get install libsqlite3-dev
After which, be sure to run
bundle update sqlite3

ERROR: While executing gem ... (ArgumentError) IPv4 address expects 4 bytes but 1 bytes - Ruby On Rails

While compiling bundle install, I got this error:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/home/bartsabayton/.rvm/rubies/ruby-2.2.0-preview1/bin/ruby -r ./siteconf20150310-8631-16gdgvg.rb extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for sqlite3_initialize()... yes
checking for sqlite3_backup_init()... yes
checking for sqlite3_column_database_name()... yes
checking for sqlite3_enable_load_extension()... yes
checking for sqlite3_load_extension()... yes
checking for sqlite3_open_v2()... yes
checking for sqlite3_prepare_v2()... yes
checking for sqlite3_int64 in sqlite3.h... yes
checking for sqlite3_uint64 in sqlite3.h... yes
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling statement.c
statement.c: In function ‘bind_param’:
statement.c:261:7: warning: implicit declaration of function ‘RBIGNUM’ [-Wimplicit-function-declaration]
statement.c:261:11: error: invalid type argument of ‘->’ (have ‘int’)
statement.c:261:32: error: ‘SIZEOF_BDIGITS’ undeclared (first use in this function)
statement.c:261:32: note: each undeclared identifier is reported only once for each function it appears in
statement.c: In function ‘reset_bang’:
statement.c:293:7: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
statement.c: In function ‘clear_bindings’:
statement.c:313:7: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
make: *** [statement.o] Error 1
make failed, exit code 2
Gem files will remain installed in /home/bartsabayton/.rvm/gems/ruby-2.2.0-preview1#e-law-landing/gems/sqlite3-1.3.8 for inspection.
Results logged to /home/bartsabayton/.rvm/gems/ruby-2.2.0-preview1#e-law-landing/extensions/x86-linux/2.2.0/sqlite3-1.3.8/gem_make.out
An error occurred while installing sqlite3 (1.3.8), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.8'` succeeds before bundling.
So I did gem install sqlite3 -v '1.3.8', but when doing this,
ERROR: While executing gem ... (ArgumentError)
IPv4 address expects 4 bytes but 1 bytes
I checked my rvm and,
RVM LIST:
bartsabayton#bartsabayton-All-Series:~/rails/landing$ rvm list
rvm rubies
ruby-2.0.0-p0 [ i686 ]
ruby-2.1.0 [ i686 ]
* ruby-2.1.3 [ i686 ]
=> ruby-2.2.0-preview1 [ i686 ]
# => - current
# =* - current && default
# * - default
I am using:
Ubuntu 12.04
Ruby 2.2.0preview1 (2014-09-17 trunk 47616) [i686-linux]
Please help. Need to fix it.
You are using Ruby 2.2.0 and this particular version of sqlite3 (1.3.8) doesn't work on it.
So, you should install a newer version of sqlite3.
You can try:
gem install sqlite3
And make sure you installed sqlite3 and sqlite-devel on your system.
Note: As Ismael noticed, you should also update Ruby.
You are using Ruby Higher versions like 2.x.x and this particular version of sqlite3 (1.3.8) have an issue.
so install sqlite3 manually using below command -
gem install sqlite3
and if still error you get delete your Gemfile.lock and then do bundle install, it works.

Cannot install sqlite3 gem on Mac OS X 10.5.8 (Leopard)

Using
Mac OS X 10.5.8 (Leopard)
ruby 1.9.3p0
gem version 1.8.14
sqlite3 Version 3.7.9
I also have installed Xcode 3.1.4 (not sure if this is used for installation of gems).
I fetched the sqlite3 gem
gem fetch sqlite3
Then unpacked it
gem unpack sqlite3-1.3.5.gem
And cd'ed into the new directory
cd sqlite3-1.3.5
Executed
ruby setup.rb config
Then cd'ed to ext/sqlite3
and then executed make
This is returning the following error messages:
usernamemac:sqlite3 username$ make
compiling backup.c
compiling database.c
database.c: In function 'initialize':
database.c:47: error: 'SQLITE_OPEN_READWRITE' undeclared (first use in this function)
database.c:47: error: (Each undeclared identifier is reported only once
database.c:47: error: for each function it appears in.)
database.c:47: error: 'SQLITE_OPEN_CREATE' undeclared (first use in this function)
database.c:79: error: 'SQLITE_OPEN_READONLY' undeclared (first use in this function)
database.c:81: warning: implicit declaration of function 'sqlite3_open_v2'
database.c: In function 'set_sqlite3_func_result':
database.c:285: error: 'sqlite3_int64' undeclared (first use in this function)
database.c:285: error: syntax error before 'long'
make: *** [database.o] Error 1
In the README.rdoc file of the gem I read about "enabling the option SQLITE_ENABLE_COLUMN_METADATA (see www.sqlite.org/compile.html for details)" but did not understand what should be done.
Can anyone please help me solve this issue?
I have tried other approaches such as
Error with MySql while doing Bundle Install
and I can't install sqlite3 gem but these did not work for me.
Update: I have similar issues when trying
rails new app1 -d mysql
create vendor/plugins/.gitkeep
run bundle install
/Users/username/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/generators/app_base.rb:232: warning: Insecure world writable dir /usr/local in PATH, mode 040777
/Users/username/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:209: warning: Insecure world writable dir /usr/local in PATH, mode 040777
Fetching source index for http://rubygems.org/
Installing rake (0.9.2.2)
...
Installing jquery-rails (1.0.19)
Installing mysql2 (0.3.11) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/username/.rbenv/versions/1.9.3-p0/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** 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
... (list of switches)
Gem files will remain installed in /Users/username/a/app1/vendor/bundle/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/username/a/app1/vendor/bundle/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
An error occured while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.
I already have the gem mysql2 (0.3.11) installed.
Update 2: When executing
gem update
I am getting the following when the sqlite3-ruby gem is being updated:
Updating sqlite3-ruby
Building native extensions. This could take a while...
/Users/username/.rbenv/versions/1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:48: warning: Insecure world writable dir /usr/local in PATH, mode 040777
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
/Users/username/.rbenv/versions/1.9.3-p0/bin/ruby extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for sqlite3_initialize()... no
checking for sqlite3_backup_init()... no
checking for sqlite3_column_database_name()... no
checking for sqlite3_enable_load_extension()... no
checking for sqlite3_load_extension()... no
creating Makefile
make
compiling backup.c
compiling database.c
database.c: In function 'initialize':
database.c:47: error: 'SQLITE_OPEN_READWRITE' undeclared (first use in this function)
database.c:47: error: (Each undeclared identifier is reported only once
database.c:47: error: for each function it appears in.)
database.c:47: error: 'SQLITE_OPEN_CREATE' undeclared (first use in this function)
database.c:79: error: 'SQLITE_OPEN_READONLY' undeclared (first use in this function)
database.c:81: warning: implicit declaration of function 'sqlite3_open_v2'
database.c: In function 'set_sqlite3_func_result':
database.c:285: error: 'sqlite3_int64' undeclared (first use in this function)
database.c:285: error: syntax error before 'long'
make: *** [database.o] Error 1
Gem files will remain installed in /Users/username/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.5 for inspection.
Results logged to /Users/username/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.5/ext/sqlite3/gem_make.out
Gems updated: activesupport, activemodel, rack, journey, sprockets, actionpack, railties, coffee-rails, jquery-rails, minitest, rubygems-update, sass-rails
Installing ri documentation for activesupport-3.2.0.rc2...
Thanks
If you are running Mac OS 10.5.X or below, you can't run sqlite3. You need at least Snow Leopard to be able to compile it.
Instead try changing your Gemfile to use sqlite3-ruby 1.2.5
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'

Resources