mysql2 icon indicating copy to clipboard operation
mysql2 copied to clipboard

Problem when installing mysql2 in Ruby 2.7.2 with dev tollkit

Open rodolfoholy opened this issue 4 years ago • 6 comments

Hi! I'm trying to bundle install and gem install mysql2 but got this error:

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

current directory:
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mysql2-0.5.3/ext/mysql2
C:/Ruby27-x64/bin/ruby.exe -I C:/Ruby27-x64/lib/ruby/2.7.0 -r
./siteconf20210129-21332-1oa9p2g.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
*** 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
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=C:/Ruby27-x64/bin/$(RUBY_BASE_NAME)
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysql-config
    --without-mysql-config
    --with-mysqlclient-dir
    --without-mysqlclient-dir
    --with-mysqlclient-include
    --without-mysqlclient-include=${mysqlclient-dir}/include
    --with-mysqlclient-lib
    --without-mysqlclient-lib=${mysqlclient-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
C:/Ruby27-x64/lib/ruby/2.7.0/mkmf.rb:1050:in `block in find_library': undefined
method `split' for nil:NilClass (NoMethodError)
    from C:/Ruby27-x64/lib/ruby/2.7.0/mkmf.rb:1050:in `collect'
    from C:/Ruby27-x64/lib/ruby/2.7.0/mkmf.rb:1050:in `find_library'
    from extconf.rb:87:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

C:/Ruby27-x64/lib/ruby/gems/2.7.0/extensions/x64-mingw32/2.7.0/mysql2-0.5.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mysql2-0.5.3 for inspection.
Results logged to
C:/Ruby27-x64/lib/ruby/gems/2.7.0/extensions/x64-mingw32/2.7.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 'http://rubygems.org/'`
succeeds before bundling.

In Gemfile:
  mysql2`

I think I got the same error when I tried to install the gem manually:

gem i mysql2-0.5.2.gem
Temporarily enhancing PATH for MSYS/MINGW...
Using msys2 packages: mingw-w64-x86_64-libmariadbclient
Building native extensions. This could take a while...
ERROR:  Error installing mysql2-0.5.2.gem:
    ERROR: Failed to build gem native extension.

current directory: C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mysql2-0.5.2/ext/mysql2
C:/Ruby27-x64/bin/ruby.exe -I C:/Ruby27-x64/lib/ruby/2.7.0 -r ./siteconf20210129-2844-1a5za8.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
*** 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
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=C:/Ruby27-x64/bin/$(RUBY_BASE_NAME)
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysql-config
    --without-mysql-config
    --with-mysqlclient-dir
    --without-mysqlclient-dir
    --with-mysqlclient-include
    --without-mysqlclient-include=${mysqlclient-dir}/include
    --with-mysqlclient-lib
    --without-mysqlclient-lib=${mysqlclient-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
C:/Ruby27-x64/lib/ruby/2.7.0/mkmf.rb:1050:in `block in find_library': undefined method `split' for nil:NilClass (NoMethodError)
    from C:/Ruby27-x64/lib/ruby/2.7.0/mkmf.rb:1050:in `collect'
    from C:/Ruby27-x64/lib/ruby/2.7.0/mkmf.rb:1050:in `find_library'
    from extconf.rb:87:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  C:/Ruby27-x64/lib/ruby/gems/2.7.0/extensions/x64-mingw32/2.7.0/mysql2-0.5.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mysql2-0.5.2 for inspection. Results logged to C:/Ruby27-x64/lib/ruby/gems/2.7.0/extensions/x64-mingw32/2.7.0/mysql2-0.5.2/gem_make.out`

Log:

have_func: checking for rb_absint_size()... -------------------- yes

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby27-x64/include/ruby-2.7.0/x64-mingw32 -IC:/Ruby27-x64/include/ruby-2.7.0/ruby/backward -IC:/Ruby27-x64/include/ruby-2.7.0 -I. -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -O3 -fno-fast-math -fstack-protector-strong conftest.c  -L. -LC:/Ruby27-x64/lib -L. -pipe -s -fstack-protector-strong     -lx64-msvcrt-ruby270  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7:   return !!argv[argc];
8: }
/* end */

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby27-x64/include/ruby-2.7.0/x64-mingw32 -IC:/Ruby27-x64/include/ruby-2.7.0/ruby/backward -IC:/Ruby27-x64/include/ruby-2.7.0 -I. -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -O3 -fno-fast-math -fstack-protector-strong conftest.c  -L. -LC:/Ruby27-x64/lib -L. -pipe -s -fstack-protector-strong     -lx64-msvcrt-ruby270  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     int (* volatile tp)(void)=(int (*)(void))&t;
12:     printf("%d", (*tp)());
13:   }
14: 
15:   return !!argv[argc];
16: }
17: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_absint_size; return !p; }
/* end */

--------------------

have_func: checking for rb_absint_singlebit_p()... -------------------- yes

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby27-x64/include/ruby-2.7.0/x64-mingw32 -IC:/Ruby27-x64/include/ruby-2.7.0/ruby/backward -IC:/Ruby27-x64/include/ruby-2.7.0 -I. -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -O3 -fno-fast-math -fstack-protector-strong conftest.c  -L. -LC:/Ruby27-x64/lib -L. -pipe -s -fstack-protector-strong     -lx64-msvcrt-ruby270  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     int (* volatile tp)(void)=(int (*)(void))&t;
12:     printf("%d", (*tp)());
13:   }
14: 
15:   return !!argv[argc];
16: }
17: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_absint_singlebit_p; return !p; }
/* end */

--------------------

have_func: checking for rb_wait_for_single_fd()... -------------------- yes

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby27-x64/include/ruby-2.7.0/x64-mingw32 -IC:/Ruby27-x64/include/ruby-2.7.0/ruby/backward -IC:/Ruby27-x64/include/ruby-2.7.0 -I. -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -O3 -fno-fast-math -fstack-protector-strong conftest.c  -L. -LC:/Ruby27-x64/lib -L. -pipe -s -fstack-protector-strong     -lx64-msvcrt-ruby270  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
conftest.c: In function 't':
conftest.c:17:57: error: 'rb_wait_for_single_fd' undeclared (first use in this function)
   17 | int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_wait_for_single_fd; return !p; }
      |                                                         ^~~~~~~~~~~~~~~~~~~~~
conftest.c:17:57: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     int (* volatile tp)(void)=(int (*)(void))&t;
12:     printf("%d", (*tp)());
13:   }
14: 
15:   return !!argv[argc];
16: }
17: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_wait_for_single_fd; return !p; }
/* end */

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby27-x64/include/ruby-2.7.0/x64-mingw32 -IC:/Ruby27-x64/include/ruby-2.7.0/ruby/backward -IC:/Ruby27-x64/include/ruby-2.7.0 -I. -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -O3 -fno-fast-math -fstack-protector-strong conftest.c  -L. -LC:/Ruby27-x64/lib -L. -pipe -s -fstack-protector-strong     -lx64-msvcrt-ruby270  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     int (* volatile tp)(void)=(int (*)(void))&t;
12:     printf("%d", (*tp)());
13:   }
14: 
15:   return !!argv[argc];
16: }
17: extern void rb_wait_for_single_fd();
18: int t(void) { rb_wait_for_single_fd(); return 0; }
/* end */

--------------------

Someone can help me?

rodolfoholy avatar Jan 29 '21 23:01 rodolfoholy

I ran into the same error, but on Ubuntu 20.04. In that case it was caused by a missing library and was fixed by installing the missing library:

sudo apt-get install default-libmysqlclient-dev

However, it looks like you're running on Windows, so you might want to check out the following section in the readme: https://github.com/brianmario/mysql2#windows

andreaslillebo avatar Feb 02 '21 05:02 andreaslillebo

Any update?

rodolfoholy avatar May 28 '21 16:05 rodolfoholy

I had a similar issue (failure in line 1050 or 1771 of mkmf.rb, with Ruby 2.7.3 from Ruby Installer on Windows). See issue #1210 on how I solved it.

pcopissa avatar Nov 11 '21 10:11 pcopissa

Linux Ubuntu 20.04.1:

I ran into this problem and running the following fixed it (as said above):

sudo apt-get install default-libmysqlclient-dev

mawilmouth avatar Jan 19 '22 01:01 mawilmouth

Solved this on Manjaro using sudo pacman -S mysql.

VictoriaAjala avatar Jun 13 '22 13:06 VictoriaAjala

I had same isssue, with:

...
Could not create Makefile due to some reason, probably lack of necessary

and did install before gem install mysql2:

# on debian/bullseye
apt install build-essential default-libmysqlclient-dev ruby2.7-dev ruby-bundler
...
gem install mysql2

mqu avatar Jul 28 '22 07:07 mqu

Centos 9 + MariaDB experience - needed to install mariadb-connector-c-devel:

yum install -y mariadb-connector-c-devel

pokrovskyy avatar Oct 11 '22 01:10 pokrovskyy

Had same problem on mac M1 Ventura 13.0 conftest.c:14:57: error: use of undeclared identifier 'rb_wait_for_single_fd' resolved with: gem 'mysql2', git: 'https://github.com/brianmario/mysql2.git', ref: 'ba4d46551d132492b34205cdb8fa224c92765bef' as this particular commit resolved it.

Faq avatar Oct 31 '22 12:10 Faq

The current release is 0.5.4 please upgrade to that version and open a new issue if this remains a problem!

sodabrew avatar Nov 01 '22 20:11 sodabrew