Tech

gem install mysql2 -v ‘0.4.10’で/usr/bin/ld: cannot find -lmysqlclientのエラーが出る

同じケースの人がいればと思ってメモ。
Redmine構築中のこと。

bundle install --without development test

を実行したら以下のエラーが出る。

(中略)
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/root/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/ext/mysql2
/root/.rbenv/versions/2.4.5/bin/ruby -I
/root/.rbenv/versions/2.4.5/lib/ruby/site_ruby/2.4.0 -r
./siteconf20190326-27431-1srwkck.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for rb_big_cmp()... yes
-----
Using mysql_config at /usr/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... no
checking for MYSQL_OPT_SSL_ENFORCE in mysql.h... no
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
-----
Setting libpath to /usr/lib64/mysql
-----
creating Makefile

current directory:
/root/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/ext/mysql2
make "DESTDIR=" clean

current directory:
/root/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
result.c: In function ‘rb_mysql_result_alloc_result_buffers’:
result.c:326:40: warning: assignment from incompatible pointer type [enabled by
default]
     wrapper->result_buffers[i].is_null = &wrapper->is_null[i];
                                        ^
result.c:328:40: warning: assignment from incompatible pointer type [enabled by
default]
     wrapper->result_buffers[i].error   = &wrapper->error[i];
                                        ^
result.c: At top level:
cc1: warning: unrecognized command line option "-Wno-self-assign" [enabled by
default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand"
[enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality"
[enabled by default]
cc1: warning: unrecognized command line option "-Wno-tautological-compare"
[enabled by default]
compiling statement.c
statement.c: In function ‘rb_raise_mysql2_stmt_error’:
statement.c:50: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:57: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:35:0,
                 from statement.c:1:
statement.c: In function ‘execute’:
./client.h:56:3: warning: ISO C90 forbids mixed declarations and code
[-Wdeclaration-after-statement]
   mysql_client_wrapper *wrapper; \
   ^
statement.c:273:3: note: in expansion of macro ‘GET_CLIENT’
   GET_CLIENT(stmt_wrapper->client);
   ^
statement.c:405: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:35:0,
                 from statement.c:1:
statement.c: In function ‘fields’:
./client.h:56:3: warning: ISO C90 forbids mixed declarations and code
[-Wdeclaration-after-statement]
   mysql_client_wrapper *wrapper; \
   ^
statement.c:481: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" [enabled by
default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand"
[enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality"
[enabled by default]
cc1: warning: unrecognized command line option "-Wno-tautological-compare"
[enabled by default]
linking shared-object mysql2/mysql2.so
/usr/bin/ld: cannot find -lmysqlclient
collect2: error: ld returned 1 exit status
make: *** [mysql2.so] Error 1

make failed, exit code 2

Gem files will remain installed in
/root/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10 for
inspection.
Results logged to
/root/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/mysql2-0.4.10/gem_make.out

An error occurred while installing mysql2 (0.4.10), and Bundler cannot
continue.
Make sure that `gem install mysql2 -v '0.4.10' --source 'https://rubygems.org/'`
succeeds before bundling.

In Gemfile:
  mysql2

というエラーがでるので、指示通り

gem install mysql2 -v '0.4.10' --source 'https://rubygems.org/'

を実行するも、

gem install mysql2 -v '0.4.10' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    current directory: /root/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/ext/mysql2
/root/.rbenv/versions/2.4.5/bin/ruby -I /root/.rbenv/versions/2.4.5/lib/ruby/site_ruby/2.4.0 -r ./siteconf20190326-381-1ij2ddh.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for rb_big_cmp()... yes
-----
Using mysql_config at /usr/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... no
checking for MYSQL_OPT_SSL_ENFORCE in mysql.h... no
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
-----
Setting libpath to /usr/lib64/mysql
-----
creating Makefile

current directory: /root/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/ext/mysql2
make "DESTDIR=" clean

current directory: /root/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
result.c: In function ‘rb_mysql_result_alloc_result_buffers’:
result.c:326:40: warning: assignment from incompatible pointer type [enabled by default]
     wrapper->result_buffers[i].is_null = &wrapper->is_null[i];
                                        ^
result.c:328:40: warning: assignment from incompatible pointer type [enabled by default]
     wrapper->result_buffers[i].error   = &wrapper->error[i];
                                        ^
result.c: At top level:
cc1: warning: unrecognized command line option "-Wno-self-assign" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
compiling statement.c
statement.c: In function ‘rb_raise_mysql2_stmt_error’:
statement.c:50: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:57: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:35:0,
                 from statement.c:1:
statement.c: In function ‘execute’:
./client.h:56:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   mysql_client_wrapper *wrapper; \
   ^
statement.c:273:3: note: in expansion of macro ‘GET_CLIENT’
   GET_CLIENT(stmt_wrapper->client);
   ^
statement.c:405: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:35:0,
                 from statement.c:1:
statement.c: In function ‘fields’:
./client.h:56:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   mysql_client_wrapper *wrapper; \
   ^
statement.c:481: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" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
linking shared-object mysql2/mysql2.so
/usr/bin/ld: cannot find -lmysqlclient
collect2: error: ld returned 1 exit status
make: *** [mysql2.so] Error 1

make failed, exit code 2

Gem files will remain installed in /root/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10 for inspection.
Results logged to /root/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/mysql2-0.4.10/gem_make.out

/usr/bin/ld: cannot find -lmysqlclient

のエラーが出て解決できない。。

結論から言うと、
/usr/lib64/内にlibmysqlclient.soが存在してたらいけた。

/usr/lib64/mysql/内に
libmysqlclient.so.18(libmysqlclient.so.18.0.0のシンボリックリンク)があったので

cp -p /usr/lib64/mysql/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so

名前変えてコピーするだけでいけた。これだけで2時間ぐらいハマった・・。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

x  Powerful Protection for WordPress, from Shield Security
このサイトは
Shield Security によって保護されています →