brianmario / mysql2

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

Failed to load libmysql.dll from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/mysql2-0.5.2-x64-mingw32/vendor/libmysql.dll #1052

Open Amol13788 opened 5 years ago

Amol13788 commented 5 years ago

I have installed the ruby ruby 2.5.3p105 (2018-10-18 revision 65156) [x64-mingw32] on docker microsoft/windowsservercore image and install the mysql2 for mariaDB connector with below commands: try with 1. gem install mysql2 -- --with-mysql-dir="C:/Program Files/MariaDB/MariaDB Connector C 64-bit"

with above option installation get success but failed to connect mariadb with above error.

try with 2. gem install mysql2 --platform=ruby -- --with-mysql-dir="C:/Program Files/MariaDB/MariaDB Connector C 64-bit"

with this option we got error like C:\Ruby25-x64\bin>gem install mysql2 --platform=ruby -- --with-mysql-dir="C:/Program Files/MariaDB/MariaDB Connector C 64-bit" Temporarily enhancing PATH for MSYS/MINGW... Installing required msys2 packages: mingw-w64-x86_64-libmariadbclient pacman failed with the following output: Building native extensions with: '--with-mysql-dir=C:/Program Files/MariaDB/MariaDB Connector C 64-bit' This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension.

current directory: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/mysql2-0.5.2/ext/mysql2

C:/Ruby25-x64/bin/ruby.exe -r ./siteconf20190611-1216-v81eb9.rb extconf.rb --with-mysql-dir=C:/Program Files/MariaDB/MariaDB Connector C 64-bit 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:/Ruby25-x64/bin/$(RUBY_BASE_NAME) --with-mysql-dir --with-mysql-include --without-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/lib

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

C:/Ruby25-x64/lib/ruby/gems/2.5.0/extensions/x64-mingw32/2.5.0/mysql2-0.5.2/mkmf.log

extconf failed, exit code 1

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

Please suggest ..

kravenoff42 commented 5 years ago

I'm having the same issue we are not using the MariaDB connector, however, just a standard connection to MySQL DB.

mkmf.log "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby25-x64/include/ruby-2.5.0/x64-mingw32 -IC:/Ruby25-x64/include/ruby-2.5.0/ruby/backward -IC:/Ruby25-x64/include/ruby-2.5.0 -I. -D_FORTIFY_SOURCE=2 -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -march=x86-64 -mtune=generic -O2 -pipe conftest.c -L. -LC:/Ruby25-x64/lib -L. -pipe -s -lx64-msvcrt-ruby250 -lgmp -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 0; 8: } /* end */

Also, we ran the same set of commands on a server that should be Identical specs, and the install went fine.

Not sure what might be gumming things up

LudwigK84 commented 4 years ago

A windows docker container (as well as a standard windows installation) does not have the Microsoft Visual C++ Redistributables installed by default. Hence you need to find the right redistributables (https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads) and install them in the docker container. If you add something like this to the dockerfile it should work.

(RUN powershell \
   [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
   Invoke-WebRequest https://aka.ms/vs/16/release/vc_redist.x64.exe -Outfile VC_redist.x64.exe
RUN powershell Start-Process VC_redist.x64.exe -Wait -ArgumentList '/install /passive /norestart')