3

I installed Ruby 2.0.0 and DevKit from RuyInstaller. I have an error message when I'm creating new project:

rails new testtest -d mysql

..... a lot of output here ........

Installing mysql2 (0.3.14)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    C:/Ruby200/bin/ruby.exe 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()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... 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... no
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.

How can I install dependencies to make this gem without any errors?

Dmitry
  • 7,457
  • 12
  • 57
  • 83

2 Answers2

9

You need MySQL 32-bit (or MySQL Connector C) to compile mysql2 gem compiling on Windows (even if you are using a 64-bit version of the OS).

Follow these steps:

  1. Download MySQL Server 32-bit .zip file (Alternatively MySQL Connector C is also fine)
  2. Copy libmysql.dll to %RUBY_HOME%\bin (or simply add MySQL 32-bit lib directory to PATH)
  3. Install mysql2 gem with --with-mysql-lib and --with-mysql-include options

    gem install mysql2 -- '--with-mysql-lib="c:\path\to\32-bit-MySQL-Server\lib\opt" --with-mysql-include="c:\\path\to\32-bit-MySQL-Server\include"'
    
Litmus
  • 10,558
  • 6
  • 29
  • 44
  • 2
    Thanks. It was really easy: `gem install mysql2 -v 0.3.14 --platform=ruby -- --with-mysql-dir=C:\mysql` – Dmitry Nov 13 '13 at 05:56
0

Here is my story. Tried to install mysql2 gem on windows 7 with devkit. First you need to install connector libraries and headers. Don't use default folder "Program Files", gem failed to include folders with spaces. I've substed connector folder through subst X:\ "C:\Program File\Mysql Connector 6 C\" and then used following cmd: gem install mysql2 -- --with-mysql-dir=X:\ Then realised that I'm using 64 bit connector libraries with 32 bit ruby. Reinstalled connector. And then gem was successfully installed. But failed to run, complaining on missing mysql dll. So, I've put libmysql.dll and *.lib to ruby\bin folder. And after all this was able to user mysql2 gem.

Nikolay Ruban
  • 981
  • 9
  • 11