【问题标题】:Error installing mysql2: ERROR: Failed to build gem native extension安装 mysql2 时出错:错误:无法构建 gem 原生扩展
【发布时间】:2019-04-03 08:30:56
【问题描述】:

我正在使用 (Mac Os)

gem 'rails', '~> 4.2.0'             # rails edge
ruby '2.2.0'
gem 'mysql2'

运行bundle 后出现此错误

安装mysql2(0.3.17)时出错,Bundler不能 继续。确保gem install mysql2 -v '0.3.17' 成功 在捆绑之前。

所以按照建议我运行

gem install mysql2 -v '0.3.17'

我不断收到这个错误,虽然我尝试了很多解决方案,不幸的是没有运气

> adware:page365 apple$ gem install mysql2 -v '0.3.17 ' Error loading
> RubyGems plugin
> "/Users/apple/.rvm/gems/ruby-2.2.0/gems/yard-0.8.7.6/lib/rubygems_plugin.rb":
> can't modify frozen Hash (RuntimeError) Building native extensions.
> This could take a while... ERROR:  Error installing mysql2:   ERROR:
> Failed to build gem native extension.
> 
>     current directory: /Users/apple/.rvm/gems/ruby-2.2.0/gems/mysql2-0.3.17/ext/mysql2
> /Users/apple/.rvm/rubies/ruby-2.2.0/bin/ruby -r
> ./siteconf20181030-12196-9cfizd.rb extconf.rb 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
> ----- Using mysql_config at /usr/local/bin/mysql_config
> ----- checking for mysql.h... yes checking for errmsg.h... yes checking for mysqld_error.h... yes
> ----- Setting rpath to /usr/local/Cellar/mysql/8.0.12/lib
> ----- creating Makefile
> 
> current directory:
> /Users/apple/.rvm/gems/ruby-2.2.0/gems/mysql2-0.3.17/ext/mysql2 make
> "DESTDIR=" clean
> 
> current directory:
> /Users/apple/.rvm/gems/ruby-2.2.0/gems/mysql2-0.3.17/ext/mysql2 make
> "DESTDIR=" compiling infile.c compiling client.c client.c:359:33:
> warning: implicit conversion loses integer precision: 'long' to
> 'unsigned int' [-Wshorten-64-to-32]
>         elapsed_time = end_time - start_time;
>                      ~ ~~~~~~~~~^~~~~~~~~~~~ client.c:431:3: error: use of undeclared identifier 'my_bool'   my_bool res =
> mysql_read_query_result(client);   ^ client.c:433:19: error: use of
> undeclared identifier 'res'   return (void *)(res == 0 ? Qtrue :
> Qfalse);
>                   ^ client.c:762:3: error: use of undeclared identifier 'my_bool'   my_bool boolval;   ^ client.c:793:7: error: use
> of undeclared identifier 'boolval'
>       boolval = (value == Qfalse ? 0 : 1);
>       ^ client.c:794:17: error: use of undeclared identifier 'boolval'
>       retval = &boolval;
>                 ^ client.c:797:10: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
>     case MYSQL_SECURE_AUTH:
>          ^~~~~~~~~~~~~~~~~
>          MYSQL_DEFAULT_AUTH /usr/local/Cellar/mysql/8.0.12/include/mysql/mysql.h:188:3: note:
> 'MYSQL_DEFAULT_AUTH' declared here   MYSQL_DEFAULT_AUTH,   ^
> client.c:798:7: error: use of undeclared identifier 'boolval'
>       boolval = (value == Qfalse ? 0 : 1);
>       ^ client.c:799:17: error: use of undeclared identifier 'boolval'
>       retval = &boolval;
>                 ^ client.c:830:38: error: use of undeclared identifier 'boolval'
>         wrapper->reconnect_enabled = boolval;
>                                      ^ client.c:1163:56: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned
> long') to 'unsigned int' [-Wshorten-64-to-32]   mysql2rb =
> mysql2_mysql_enc_name_to_rb(charset_name, charset_name_len);
>              ~~~~~~~~~~~~~~~~~~~~~~~~~~~               ^~~~~~~~~~~~~~~~ client.c:1196:38: error: use of undeclared identifier
> 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?   return
> _mysql_client_options(self, MYSQL_SECURE_AUTH, value);
>                                      ^~~~~~~~~~~~~~~~~
>                                      MYSQL_DEFAULT_AUTH /usr/local/Cellar/mysql/8.0.12/include/mysql/mysql.h:188:3: note:
> 'MYSQL_DEFAULT_AUTH' declared here   MYSQL_DEFAULT_AUTH,   ^ 2
> warnings and 10 errors generated. make: *** [client.o] Error 1
> 
> make failed, exit code 2
> 
> Gem files will remain installed in
> /Users/apple/.rvm/gems/ruby-2.2.0/gems/mysql2-0.3.17 for inspection.
> Results logged to
> /Users/apple/.rvm/gems/ruby-2.2.0/extensions/x86_64-darwin-18/2.2.0/mysql2-0.3.17/gem_make.out

任何帮助将不胜感激!

【问题讨论】:

    标签: ruby-on-rails-4 mysql2 ruby-2.2


    【解决方案1】:

    安装mysql2依赖后安装gem

    brew install mysql-client libmysqlclient-dev
    

    【讨论】:

    • 谢谢,它为我指明了正确的方向(linux):sudo apt install mysql-client libmysqlclient-dev
    【解决方案2】:

    要修复它,我只需使用捆绑器安装 mysql2 gem。

    安装mysql2 gem:

    $ bundle install
    $ bundle exec gem install mysql2
    

    【讨论】:

      猜你喜欢
      • 2013-11-14
      • 1970-01-01
      • 2015-03-06
      • 2011-04-06
      • 1970-01-01
      • 2020-10-16
      • 2017-05-16
      • 2013-11-09
      • 2012-04-19
      相关资源
      最近更新 更多