Bug #8591
closed[BUG] Segmentation fault ruby 2.0.0p195 (2013-05-14) [x64-mingw32]
Description
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
Files
Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago
- Status changed from Open to Third Party's Issue
It seems like a problem of mysql2.
see also https://github.com/brianmario/mysql2/issues/372
Updated by phasis68 (Heesob Park) over 11 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.
gendef.exe libmysql.dll
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="..."
NOTE:
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
Updated by alpracka (Nikos Timiopulos) over 11 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:/
Programs/MySQL/MySQL_Server_5.6/include
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?
Updated by aaron@serendipity.cx (Aaron Stone) almost 11 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?
Updated by phasis68 (Heesob Park) almost 11 years ago
mysql2-0.3.14 gem still fails with version checking with Connect/C 6.1.2.
C:>irb
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.
from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:4
5:in require' from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:4 5:in
require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/lib/mysql2.rb
:8:in <top (required)>' from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:1 10:in
require'
from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:1
10:in rescue in require' from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:3 5:in
require'
from (irb):1
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_lib_iname')
end
The main problem is that linking using an MSVC-generated x64 *.lib file is not supported on mingw-w64 complier.
http://sourceforge.net/apps/trac/mingw-w64/wiki/Answer%2064%20bit%20MSVC-generated%20x64%20.lib
It is desired that MySQL could provide two versions of libmysql.lib, the current mvsc-generated version and mingw-w64 dlltool generated version.
Updated by aaron@serendipity.cx (Aaron Stone) almost 11 years ago
Let's move the conversation to https://github.com/brianmario/mysql2/issues/469
Updated by nobu (Nobuyoshi Nakada) almost 11 years ago
- Has duplicate Bug #9411: Rails server not started with Ruby(ruby 2.0.0p353 (2013-11-22) [x64-mingw32] with Rails 4.0.2 and MySQL Server 5.6) added
Updated by nobu (Nobuyoshi Nakada) over 10 years ago
- Related to Bug #9958: rails server error added
Updated by nobu (Nobuyoshi Nakada) almost 10 years ago
- Has duplicate Bug #10834: Segmentation fault when I try to do rails server in Windows 7 home edition 64bits added