brianmario / mysql2

A modern, simple and very fast Mysql library for Ruby - binding to libmysql
http://github.com/brianmario/mysql2
MIT License
2.25k stars 551 forks source link

Unable to install ruby gem #1120

Open ughstudios opened 4 years ago

ughstudios commented 4 years ago
Fetching mysql2 0.3.21
Installing mysql2 0.3.21 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/decil/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/mysql2-0.3.21/ext/mysql2
/home/decil/.rbenv/versions/2.7.1/bin/ruby -I /home/decil/.rbenv/versions/2.7.1/lib/ruby/2.7.0 -r
./siteconf20200529-74-1nvszd4.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/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Setting libpath to /usr/lib/x86_64-linux-gnu
-----
creating Makefile

current directory: /home/decil/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR=" clean

current directory: /home/decil/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR="
compiling client.c
client.c: In function ‘nogvl_read_query_result’:
client.c:439:3: error: unknown type name ‘my_bool’; did you mean ‘bool’?
  439 |   my_bool res = mysql_read_query_result(client);
      |   ^~~~~~~
      |   bool
client.c: In function ‘rb_query’:
client.c:687:14: warning: passing argument 1 of ‘rb_rescue2’ from incompatible pointer type
[-Wincompatible-pointer-types]
  687 |   rb_rescue2(do_send_query, (VALUE)&args, disconnect_and_raise, self, rb_eException, (VALUE)0);
      |              ^~~~~~~~~~~~~
      |              |
      |              VALUE (*)(void *) {aka long unsigned int (*)(void *)}
In file included from /home/decil/.rbenv/versions/2.7.1/include/ruby-2.7.0/ruby.h:33,
                 from ./mysql2_ext.h:8,
                 from client.c:1:
/home/decil/.rbenv/versions/2.7.1/include/ruby-2.7.0/ruby/ruby.h:1988:18: note: expected ‘VALUE (*)(VALUE)’ {aka ‘long
unsigned int (*)(long unsigned int)’} but argument is of type ‘VALUE (*)(void *)’ {aka ‘long unsigned int (*)(void *)’}
 1988 | VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...);
      |                  ^~~~~~~~~~~~~~~
client.c:695:16: warning: passing argument 1 of ‘rb_rescue2’ from incompatible pointer type
[-Wincompatible-pointer-types]
  695 |     rb_rescue2(do_query, (VALUE)&async_args, disconnect_and_raise, self, rb_eException, (VALUE)0);
      |                ^~~~~~~~
      |                |
      |                VALUE (*)(void *) {aka long unsigned int (*)(void *)}
In file included from /home/decil/.rbenv/versions/2.7.1/include/ruby-2.7.0/ruby.h:33,
                 from ./mysql2_ext.h:8,
                 from client.c:1:
/home/decil/.rbenv/versions/2.7.1/include/ruby-2.7.0/ruby/ruby.h:1988:18: note: expected ‘VALUE (*)(VALUE)’ {aka ‘long
unsigned int (*)(long unsigned int)’} but argument is of type ‘VALUE (*)(void *)’ {aka ‘long unsigned int (*)(void *)’}
 1988 | VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...);
      |                  ^~~~~~~~~~~~~~~
client.c: In function ‘_mysql_client_options’:
client.c:762:3: error: unknown type name ‘my_bool’; did you mean ‘bool’?
  762 |   my_bool boolval;
      |   ^~~~~~~
      |   bool
client.c:797:10: error: ‘MYSQL_SECURE_AUTH’ undeclared (first use in this function); did you mean ‘MYSQL_DEFAULT_AUTH’?
  797 |     case MYSQL_SECURE_AUTH:
      |          ^~~~~~~~~~~~~~~~~
      |          MYSQL_DEFAULT_AUTH
client.c:797:10: note: each undeclared identifier is reported only once for each function it appears in
client.c: In function ‘set_secure_auth’:
client.c:1185:38: error: ‘MYSQL_SECURE_AUTH’ undeclared (first use in this function); did you mean ‘MYSQL_DEFAULT_AUTH’? 1185 |   return _mysql_client_options(self, MYSQL_SECURE_AUTH, value);
      |                                      ^~~~~~~~~~~~~~~~~
      |                                      MYSQL_DEFAULT_AUTH
client.c:1186:1: warning: control reaches end of non-void function [-Wreturn-type]
 1186 | }
      | ^
client.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-self-assign’
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
make: *** [Makefile:245: client.o] Error 1

make failed, exit code 2

Gem files will remain installed in /home/decil/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/mysql2-0.3.21 for
inspection.
Results logged to
/home/decil/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/extensions/x86_64-linux/2.7.0/mysql2-0.3.21/gem_make.out

An error occurred while installing mysql2 (0.3.21), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.21' --source 'http://rubygems.org/'` succeeds before bundling.

In Gemfile:
  mysql2

Has anyone seen this before? How do I resolve this?

Nef10 commented 4 years ago

You are using a very outdated version. The bug with my_bool is known and has been fixed, see #980

You need to update mysql2 to at least 0.4.10

diegobentes commented 4 years ago

Has anyone managed to solve this? I have the same problem, but I can't update for summer 0.4.x because ActiveRecord and rails are in version 3. I am trying to solve for days and I am nowhere near a solution.

sourabhkt commented 4 years ago

We are also facing this issue and can't upgrade to 0.4.x because it's incompatible with our rails/activerecord version.

diegobentes commented 4 years ago

Hello @sourabhkt , so, in order for me to run, I needed to put it in a docker with an older operating system. I used this images and managed to make it work and see my changes.

Do you use a newer system like ubuntu 20? If so, that could be the reason, but I'm not sure. My docker file:

FROM zrpaplicacoes/docker-in-rails:2.2.10

EXPOSE 3000
WORKDIR /home/app

COPY Gemfile .
COPY Gemfile.lock .

ENV RUNTIME_PACKAGES="mysql mysql-dev mysql-client libxslt-dev linux-headers imagemagick imagemagick-dev nodejs"

RUN apk add --no-cache $RUNTIME_PACKAGES && \
    gem update bundler
airblade commented 3 years ago

If you're on v0.3.x, you have to use mysql 5.7; mysql 8.0 removed the my_bool datatype (see #840).

Serhii-Danovsky commented 3 years ago

Fix

gem install mysql2 -v '0.3.21' -- --srcdir=/usr/local/mysql/include

mysql Ver 14.14 Distrib 5.7.35, for Linux (x86_64) using EditLine wrapper Rails 4 Ruby 2.7.3

ylluminarious commented 2 years ago

@airblade Thanks for the advice. I also needed to install MySQL 5.7. I was finally able to get the gem to install correctly as part of bundle install, through the instructions found here: https://askubuntu.com/questions/1259242/unable-to-install-mysql-5-7-on-ubuntu-20-04