File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 3
3
require 'bigdecimal'
4
4
require 'rational' unless RUBY_VERSION >= '1.9.2'
5
5
6
+ # Load libmysql.dll before requiring mysql2/mysql2.so
7
+ # This gives a chance to be flexible about the load path
8
+ # Or to bomb out with a clear error message instead of a linker crash
9
+ if RUBY_PLATFORM =~ /mswin|mingw/
10
+ dll_search = [
11
+ File . expand_path ( '../vendor/libmysql.dll' , File . dirname ( __FILE__ ) ) . gsub ( '/' , '\\' ) ,
12
+ File . expand_path ( '../libmysql.dll' , File . dirname ( __FILE__ ) ) . gsub ( '/' , '\\' ) ,
13
+ 'libmysql.dll' # This will use default / system library paths
14
+ ]
15
+
16
+ # If this environment variable is set, it overrides any other search paths
17
+ dll_search = [ ENV [ 'RUBY_MYSQL2_LIBMYSQL_DLL' ] . dup ] if ENV [ 'RUBY_MYSQL2_LIBMYSQL_DLL' ]
18
+
19
+ require 'Win32API'
20
+ LoadLibrary = Win32API . new ( 'Kernel32' , 'LoadLibrary' , [ 'P' ] , 'I' )
21
+ unless dll_search . any? { |dll | 0 != LoadLibrary . call ( dll ) }
22
+ abort "Failed to load libmysql.dll from any of #{ dll_search . inspect } "
23
+ end
24
+ end
25
+
6
26
require 'mysql2/version' unless defined? Mysql2 ::VERSION
7
27
require 'mysql2/error'
8
28
require 'mysql2/mysql2'
You can’t perform that action at this time.
0 commit comments