C - 无法在 CentOS 7 上安装 MySQL2,并显示 libmysqlclient 错误



当我用gem安装mysql2时,我遇到了一些困惑。我被困扰了两天。我已经尝试了所有这些命令:

gem install mysql2 -v '0.5.1' --source 'https://gems.ruby-china.com/'  -- --with-mysql-lib="/usr/lib/mysql"
gem install mysql2 -v '0.5.1' --source 'https://gems.ruby-china.com/'  -- --with-mysql-lib="/usr/lib64/mysql"
gem install mysql2 -v '0.5.1' --source 'https://gems.ruby-china.com/'

但所有这些都给我返回了相同的错误,如下所示:

Building native extensions with: '--with-mysql-lib=/usr/lib/mysql'
This could take a while...
ERROR:  Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/mysql2-0.5.1/ext/mysql2
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20180719-13223-afd0n0.rb extconf.rb --with-mysql-lib=/usr/lib/mysql
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 /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
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... yes
Setting libpath to /usr/lib64/mysql
creating Makefile
current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/mysql2-0.5.1/ext/mysql2
make "DESTDIR=" clean
current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/mysql2-0.5.1/ext/mysql2
make "DESTDIR="
compiling client.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 forbenter code hereids mixed declarations and code [-Wdeclaration-after-statement]
rb_encoding *default_internal_enc = rb_default`enter code here`_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);
^
compiling mysql2_ext.c
compiling infile.c
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 /usr/local/rvm/gems/ruby-2.3.0/gems/mysql2-0.5.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/mysql2-0.5.1/gem_make.out

这是我所有关于mysql 的文件

您缺少mysqlclient。

请尝试以下步骤:Ruby gem mysql2安装失败的

在OSX上,尝试brew install mysql-connector-c

最糟糕的情况是,您可能需要卸载mysql并重新安装:https://github.com/brianmario/mysql2/issues/687#issuecomment-144811470

相关内容

最新更新