[BUG] Segmentation fault ruby 2.0.0p195 (2013-05-14) [x64-mingw32]
rails server crashes with Segmentation fault
in pure app created with rails new .
after installing mysql2 gem like this
gem install mysql2 -v '0.3.12b6' -- --with-opt-dir="C:\work\mysqlconnectorc61"
On Windows 7 64b with ruby 2.0 64b in C:\Ruby200-x64 installed by ruby installer rubyinstaller-2.0.0-p195-x64.exe, devkit DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe and mysql connector mysql-connector-c-6.1.0-winx64.msi.
without gem 'mysql2', '~>0.3.12b6' with gem 'sqlite3' server runs fine
#2 [ruby-core:55771] Updated by Heesob Park over 3 years ago
The libmysql.lib included in the MySQL Connector/C 64 bit is not compatible with the mingw64-gcc compiler.
You need to generate mingw64 compatible libmysql.lib file.
To generate libmysql.lib file, you need gendef.exe, which can obtain from mingw-w64 distribution(I got from https://structure-svm-map.googlecode.com/files/svm-map-win.zip)
In the lib folder of the mysql connector, produce libmysql.lib with the following steps.
dlltool -v --dllname libmysql.dll --def libmysql.def --output-lib libmysql.lib
And running the normal gem install command.
gem install mysql2 -v '0.3.12b6' -- --with-opt-dir="..."
In case of MySQL Connector/C 6.1, due to the version comparison routine, you cannot use mysql2 module with the following exception.
RuntimeError: Incorrect MySQL client library version! This gem was compiled for 5.7.2-m12 but the client library is 6.1.0.
You should use mysql-connector-c-6.0.2-winx64.msi in http://dev.mysql.com/downloads/connector/c/6.0.html#downloads
#3 Updated by Nikos Timiopulos over 3 years ago
Hi, I can confirm phasis68's solution works. I've just came through these steps on Windows 8 (x64) with Ruby 2.0.0-p247 (x64), MySQL 5.6.13 (x86, 64-bit).
I haven't used the connector 6.0.2. At first I compiled new libmysql.lib (as described above) from the libmysql.dll provided by MySQL lib folder. Than I installed mysql2 gem like this:
gem install mysql2 -- --with-mysql-dir=D:/Programs/MySQL/MySQL_Server_5.6/bin --with-mysql-lib=D:/Programs/MySQL/MySQL_Server_5.6/lib --with-mysql-include=D:/
And finally, copy the libmysql.dll to the Ruby bin directory. It seems to work fine so far. There is only one WARNING which is showing every time when rails server starts, or rake db commands are executed, etc.:
DL is deprecated, please use Fiddle
So I wanna ask: is it problem and can it be solved?
#4 [ruby-core:59335] Updated by Aaron Stone almost 3 years ago
This is a great find! I've been wondering what on earth the problem was. (Wish I had seen this bug months ago.)
The DL warning is just a warning, it's not a problem.
The MySQL Connector/C 6.1 should work fine in mysql2 >= 0.3.12, we fixed the version check.
Is there a way we can detect the missing gendef state and instruct the user to fix their libmysql.dll? Either at compile or load time. Should this bug be reported upstream as well, so that MySQL begins building their DLLs with the right info baked in?
#5 [ruby-core:59336] Updated by Heesob Park almost 3 years ago
mysql2-0.3.14 gem still fails with version checking with Connect/C 6.1.2.
DL is deprecated, please use Fiddle
irb(main):001:0> require 'mysql2'
RuntimeError: Incorrect MySQL client library version! This gem was compiled for
6.1.2 but the client library is 6.0.0.
rescue in require'require'
from C:/Ruby200-x64/bin/irb:12:in `'
You can detect the wrong library file in extconf.rb like this:
if RUBY_PLATFORM =~ /x64-mingw32/
abort "-----\nWrong version of libmysql.lib\n-----" unless have_func('_libmysql_libiname')
The main problem is that linking using an MSVC-generated x64 *.lib file is not supported on mingw-w64 complier.
It is desired that MySQL could provide two versions of libmysql.lib, the current mvsc-generated version and mingw-w64 dlltool generated version.