5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby2.6.x WSLでbrewを使用し、bundle installのmysqlでコケる際の対処。

Posted at

tl;dr

WSLのbrewで管理しているのであれば

$ bundle config --local build.mysql2 "--with-ldflags=-L/home/linuxbrew/.linuxbrew/opt/openssl/lib"

上記コマンド後にbundle installで多分解決します。

状態

Using kaminari-core 1.1.1                                                                                                                 
Using kaminari-actionview 1.1.1                                                                                                           
Using kaminari-activerecord 1.1.1                                                                                                         
Using kaminari 1.1.1                                                                                                                      
Using launchy 2.4.3                                                                                                                       
Using ruby_dep 1.5.0                                                                                                                      
Using listen 3.1.5                                                                                                                        
Fetching mysql2 0.5.2                                                                                                                     
Installing mysql2 0.5.2 with native extensions                                                                                            
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.                                                                        
                                                                                                                                          
    current directory: /home/iruk/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/mysql2-0.5.2/ext/mysql2                                  
/home/iruk/.rbenv/versions/2.6.0/bin/ruby -I /home/iruk/.rbenv/versions/2.6.0/lib/ruby/2.6.0 -r ./siteconf20190507-7094-1spvp3a.rb        
extconf.rb --with-ldflags\=-L/usr/local/opt/openssl/lib                                                                                   
checking for rb_absint_size()... yes                                                                                                      
checking for rb_absint_singlebit_p()... yes                                                                                               
checking for rb_wait_for_single_fd()... yes                                                                                               
-----                                                                                                                                     
Using mysql_config at /home/linuxbrew/.linuxbrew/bin/mysql_config                                                                         
-----                                                                                                                                     
checking for mysql.h... yes                                                                                                               
checking for errmsg.h... yes                                                                                                              
checking for SSL_MODE_DISABLED in mysql.h... yes                                                                                          
checking for SSL_MODE_PREFERRED in mysql.h... yes                                                                                         
checking for SSL_MODE_REQUIRED in mysql.h... yes                                                                                          
checking for SSL_MODE_VERIFY_CA in mysql.h... yes                                                                                         
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes                                                                                   
checking for MYSQL.net.vio in mysql.h... yes                                                                                              
checking for MYSQL.net.pvio in mysql.h... no                                                                                              
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes                                                                              
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes                                                                            
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes                                                                                 
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes                                                                                      
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes                                                                           
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes                                                                          
checking for my_bool in mysql.h... no                                                                                                     
-----                                                                                                                                     
Setting libpath to /home/linuxbrew/.linuxbrew/Cellar/mysql/8.0.16/lib                                                                     
-----                                                                                                                                     
creating Makefile                                                                                                                         
                                                                                                                                          
current directory: /home/iruk/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/mysql2-0.5.2/ext/mysql2                                      
make "DESTDIR=" clean                                                                                                                     
                                                                                                                                          
current directory: /home/iruk/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/mysql2-0.5.2/ext/mysql2                                      
make "DESTDIR="                                                                                                                           
compiling client.c                                                                                                                        
In file included from ./mysql2_ext.h:39:0,                                                                                                
                 from client.c:1:                                                                                                         
client.c: In function ‘rb_set_ssl_mode_option’:                                                                                           
./client.h:22:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]                                     
   mysql_client_wrapper *wrapper; \                                                                                                       
   ^                                                                                                                                      
client.c:127:3: note: in expansion of macro ‘GET_CLIENT’                                                                                  
   GET_CLIENT(self);                                                                                                                      
   ^~~~~~~~~~                                                                                                                             
client.c:128:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]                                      
   int val = NUM2INT( setting );                                                                                                          
   ^~~                                                                                                                                    
client.c:133:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]                                      
   int result = mysql_options( wrapper->client, MYSQL_OPT_SSL_MODE, &val );                                                               
   ^~~                                                                                                                                    
client.c: At top level:                                                                                                                   
cc1: warning: unrecognized command line option ‘-Wno-self-assign’                                                                         
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’                                                                
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’                                                            
cc1: warning: unrecognized command line option ‘-Wno-cast-function-type’                                                                  
compiling infile.c                                                                                                                        
compiling mysql2_ext.c                                                                                                                    
compiling result.c                                                                                                                        
compiling statement.c                                                                                                                     
statement.c: In function ‘rb_raise_mysql2_stmt_error’:                                                                                    
statement.c:47:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]                                    
   VALUE rb_error_msg = rb_str_new2(mysql_stmt_error(stmt_wrapper->stmt));                                                                
   ^~~~~                                                                                                                                  
statement.c:53:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]                                    
   rb_encoding *default_internal_enc = rb_default_internal_encoding();                                                                    
   ^~~~~~~~~~~                                                                                                                            
In file included from ./mysql2_ext.h:39:0,                                                                                                
                 from statement.c:1:                                                                                                      
statement.c: In function ‘rb_mysql_stmt_execute’:                                                                                         
./client.h:22:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]                                     
   mysql_client_wrapper *wrapper; \                                                                                                       
   ^                                                                                                                                      
statement.c:261:3: note: in expansion of macro ‘GET_CLIENT’                                                                               
   GET_CLIENT(stmt_wrapper->client);                                                                                                      
   ^~~~~~~~~~                                                                                                                             
statement.c:389:13: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]                                  
             VALUE rb_val_as_string = rb_funcall(argv[i], intern_to_s, 0);                                                                
             ^~~~~                                                                                                                        
In file included from ./mysql2_ext.h:39:0,                                                                                                
                 from statement.c:1:                                                                                                      
statement.c: In function ‘rb_mysql_stmt_fields’:                                                                                          
./client.h:22:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]                                     
   mysql_client_wrapper *wrapper; \                                                                                                       
   ^                                                                                                                                      
statement.c:491:3: note: in expansion of macro ‘GET_CLIENT’                                                                               
   GET_CLIENT(stmt_wrapper->client);                                                                                                      
   ^~~~~~~~~~                                                                                                                             
statement.c: At top level:                                                                                                                
cc1: warning: unrecognized command line option ‘-Wno-self-assign’                                                                         
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’                                                                
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’                                                            
cc1: warning: unrecognized command line option ‘-Wno-cast-function-type’                                                                  
linking shared-object mysql2/mysql2.so                                                                                                    
/usr/bin/ld: cannot find -lssl                                                                                                            
/usr/bin/ld: cannot find -lcrypto                                                                                                         
collect2: error: ld returned 1 exit status                                                                                                
Makefile:259: recipe for target 'mysql2.so' failed                                                                                        
make: *** [mysql2.so] Error 1                                                                                                             
                                                                                                                                          
make failed, exit code 2                                                                                                                  
                                                                                                                                          
Gem files will remain installed in /home/iruk/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/mysql2-0.5.2 for inspection.                 
Results logged to /home/iruk/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0-static/mysql2-0.5.2/gem_make.out     
                                                                                                                                          
An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.                                                           
Make sure that `gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'` succeeds before bundling.                                 
                                                                                                                                          
In Gemfile:                                                                                                                               
  mysql2                                                                                                                                  

MacOS

参考 : mysql2 gemインストール時のトラブルシュート

/usr/bin/ld: cannot find -lssl

この部分が問題となっており、MacOSにおける解決の為のコマンドとしては下記コマンドになります。

$ gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/' -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib

しかし、WSLのbrewではopensllの存在するディレクトリが違うため上記コマンドでは問題の解決には至りません。

WSL

最初のエラー文を眺めると、

-----                                                                                                                                     
Setting libpath to /home/linuxbrew/.linuxbrew/Cellar/mysql/8.0.16/lib                                                                     
-----    

とあります。
WSLのbrewでは/home/linuxbrew/.linuxbrew/Cellar以下で管理をしているようですね。

 
 
では上記のbundle configを上記ディレクトリに合うように書き換えると、最初のコマンドになります。

$ bundle config --local build.mysql2 "--with-ldflags=-L/home/linuxbrew/.linuxbrew/opt/openssl/lib"

これでopensllを読み取れるようになってbundle installを正常にパスできるはず。

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?