【问题标题】:An error occurred while installing mysql (2.9.1), and Bundler cannot continue安装mysql(2.9.1)时出错,Bundler无法继续
【发布时间】:2020-06-02 21:37:51
【问题描述】:

在此之前,我收到两个堆栈跟踪错误。它们是:

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': 

 The compiler failed to generate an executable file. (RuntimeError). 
 You have to install development tools first.

    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:782:in `try_func'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1069:in `block in have_func'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1068:in `have_func'

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200218-95654-zjppya.rb extconf.rb
checking for mysql_ssl_set()... *** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

这是主要错误:或者捆绑器告诉我的内容:

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

我已经做了很多研究。

解决方案 1(安装正确的开发者工具):

安装xcode和xcode开发者工具,运行命令:

xcode-select --install

我明白了:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

我正在进行的项目需要 ruby​​ 版本 1.9.3。

我真的不知道该怎么做,因为我不知道标头是什么,并且通过捆绑程序输入了很多命令并重置 xcode 以及删除工具并重新安装。当我使用 bundle clean --force 我得到:

Could not find mysql-2.9.1 in any of the sources

我该怎么办?我查看了与此相关的其他人,但命令并没有解决它,而且我对 mysql 2.9.1 完全没有任何了解。

编辑:我应该把它贴进去,因为它要求我确保它有效:

mysql-2.9.1 git:(testupdategem) ✗ sudo gem install mysql -v '2.9.1'
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
    ERROR: Failed to build gem native extension.

        /Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/bin/ruby extconf.rb
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... yes
checking for rb_thread_start_timer()... no
checking for mysql.h... yes
creating Makefile

make
compiling mysql.c
mysql.c:79:2: error: unknown type name 'my_bool'
        my_bool *is_null;
        ^
mysql.c:361:5: error: use of undeclared identifier 'my_bool'
    my_bool b;
    ^
mysql.c:391:10: error: use of undeclared identifier 'MYSQL_SET_CLIENT_IP'; did you mean 'MYSQL_SET_CHARSET_DIR'?
    case MYSQL_SET_CLIENT_IP:
         ^~~~~~~~~~~~~~~~~~~
         MYSQL_SET_CHARSET_DIR
/usr/local/Cellar/mysql/8.0.19/include/mysql/mysql.h:176:3: note: 'MYSQL_SET_CHARSET_DIR' declared here
  MYSQL_SET_CHARSET_DIR,
  ^
mysql.c:398: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.19/include/mysql/mysql.h:187:3: note: 'MYSQL_DEFAULT_AUTH' declared here
  MYSQL_DEFAULT_AUTH,
  ^
mysql.c:400:6: error: use of undeclared identifier 'b'
            b = 1;
            ^
mysql.c:402:6: error: use of undeclared identifier 'b'
            b = 0;
            ^
mysql.c:403:14: error: use of undeclared identifier 'b'
        v = (char*)&b;
                    ^
mysql.c:391:10: error: duplicate case value 'MYSQL_SET_CHARSET_DIR'
    case MYSQL_SET_CLIENT_IP:
         ^
mysql.c:384:10: note: previous case defined here
    case MYSQL_SET_CHARSET_DIR:
         ^
mysql.c:588:9: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'unsigned int' [-Wshorten-64-to-32]
    n = mysql_num_rows(res);
      ~ ^~~~~~~~~~~~~~~~~~~
mysql.c:633:9: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'unsigned int' [-Wshorten-64-to-32]
    n = mysql_num_rows(res);
      ~ ^~~~~~~~~~~~~~~~~~~
mysql.c:878:5: error: use of undeclared identifier 'my_bool'
    my_bool true = 1;
    ^
mysql.c:883:61: error: cannot take the address of an rvalue of type 'int'
    if (mysql_stmt_attr_set(s, STMT_ATTR_UPDATE_MAX_LENGTH, &true))
                                                            ^~~~~
mysql.c:1068:73: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                int len = strlen(fields[i].table)+strlen(fields[i].name)+1;
                    ~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
mysql.c:1661:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
    n = mysql_stmt_param_count(s->stmt);
      ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mysql.c:2049:52: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
    rb_define_const(cMysql, "SECURE_AUTH", INT2NUM(MYSQL_SECURE_AUTH));
                                                   ^~~~~~~~~~~~~~~~~
                                                   MYSQL_DEFAULT_AUTH
/Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/ruby.h:973:35: note: expanded from macro 'INT2NUM'
# define INT2NUM(v) INT2FIX((int)(v))
                                  ^
/Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/ruby.h:225:45: note: expanded from macro 'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^
/usr/local/Cellar/mysql/8.0.19/include/mysql/mysql.h:187:3: note: 'MYSQL_DEFAULT_AUTH' declared here
  MYSQL_DEFAULT_AUTH,
  ^
mysql.c:2050:61: error: use of undeclared identifier 'MYSQL_OPT_GUESS_CONNECTION'; did you mean 'MYSQL_OPT_RECONNECT'?
    rb_define_const(cMysql, "OPT_GUESS_CONNECTION", INT2NUM(MYSQL_OPT_GUESS_CONNECTION));
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~
                                                            MYSQL_OPT_RECONNECT
/Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/ruby.h:973:35: note: expanded from macro 'INT2NUM'
# define INT2NUM(v) INT2FIX((int)(v))
                                  ^
/Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/ruby.h:225:45: note: expanded from macro 'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^
/usr/local/Cellar/mysql/8.0.19/include/mysql/mysql.h:185:3: note: 'MYSQL_OPT_RECONNECT' declared here
  MYSQL_OPT_RECONNECT,
  ^
mysql.c:2051:68: error: use of undeclared identifier 'MYSQL_OPT_USE_EMBEDDED_CONNECTION'
    rb_define_const(cMysql, "OPT_USE_EMBEDDED_CONNECTION", INT2NUM(MYSQL_OPT_USE_EMBEDDED_CONNECTION));
                                                                   ^
mysql.c:2052:66: error: use of undeclared identifier 'MYSQL_OPT_USE_REMOTE_CONNECTION'
    rb_define_const(cMysql, "OPT_USE_REMOTE_CONNECTION", INT2NUM(MYSQL_OPT_USE_REMOTE_CONNECTION));
                                                                 ^
mysql.c:2053:54: error: use of undeclared identifier 'MYSQL_SET_CLIENT_IP'; did you mean 'MYSQL_SET_CHARSET_DIR'?
    rb_define_const(cMysql, "SET_CLIENT_IP", INT2NUM(MYSQL_SET_CLIENT_IP));
                                                     ^~~~~~~~~~~~~~~~~~~
                                                     MYSQL_SET_CHARSET_DIR
/Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/ruby.h:973:35: note: expanded from macro 'INT2NUM'
# define INT2NUM(v) INT2FIX((int)(v))
                                  ^
/Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/ruby.h:225:45: note: expanded from macro 'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^
/usr/local/Cellar/mysql/8.0.19/include/mysql/mysql.h:176:3: note: 'MYSQL_SET_CHARSET_DIR' declared here
  MYSQL_SET_CHARSET_DIR,
  ^
In file included from mysql.c:2287:
./error_const.h:2608:27: error: use of undeclared identifier 'ER_XPLUGIN_IP'
    rb_define_mysql_const(ER_XPLUGIN_IP);
                          ^
4 warnings and 16 errors generated.
make: *** [mysql.o] Error 1


Gem files will remain installed in /Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/gems/1.9.1/gems/mysql-2.9.1 for inspection.
Results logged to /Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/gems/1.9.1/gems/mysql-2.9.1/ext/mysql_api/gem_make.out

说明:使用\curl -sSL https://get.rvm.io | bash -s stable 安装RVM;重新启动你的外壳;使用 rvm install 1.9.3 安装 Ruby。

 Error running 'env GEM_HOME=/Users/tblevins/.rvm/gems/ruby-1.9.3- 
 p551@global GEM_PATH= /Users/tblevins/.rvm/rubies/ruby-1.9.3- 
 p551/bin/ruby -d /Users/tblevins/.rvm/src/rubygems-3.0.7/setup.rb -- 
 no-document', please read /Users/tblevins/.rvm/log/1582058102_ruby- 
 1.9.3-p551/rubygems.install.log 

说这是 ruby​​gems.install.log 文件:

 Exception LoadError' at /Users/tblevins/.rvm/rubies/ruby-1.9.3- 
 p551/lib/ruby/1.9.1/rubygems.rb:1264 - cannot load such file -- 
 rubygems/defaults/operating_system Exception LoadError' at /. 
 Users/tblevins/.rvm/rubies/ruby-1.9.3- 
 p551/lib/ruby/1.9.1/rubygems.rb:1273 - cannot load such file -- 
 rubygems/defaults/ruby. AND /Users/tblevins/.rvm/src/rubygems- 
 3.0.7/lib/rubygems/core_ext/kernel_warn.rb:18: void value expression 
 /Users/tblevins/.rvm/src/rubygems- 
 3.0.7/lib/rubygems/core_ext/kernel_warn.rb:43: syntax error, 
 unexpected '}', expecting keyword_end 

对于未来的观众:我必须这样做:

gem install mysql -- --with-cflags=\"-I/usr/local/opt/openssl/include\" --with-ldflags=\"-L/usr/local/opt/openssl/lib\"

我还必须清理我的 brew 并链接 git/node。这是很多尝试和失败,我很抱歉我不记得所有这一切。

我也这样做了:

bundle config --local build.mysql “--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

捆绑器版本 1.16.4 Ruby 版本 1.9.3-p551

【问题讨论】:

  • 请你试试sudo gem install mysql -v '2.9.1' 让我知道输出
  • @rahulmishra 我编辑了帖子以添加它
  • 您系统中的 mysql 版本是什么,以前它在哪个 mysql 版本上工作? mysql --version
  • 我不知道,我是项目的新手,我正在尝试让 bundle install 工作,这样我就可以开始工作了。这些系统就像 10 年前一样安装。
  • \curl -sSL https://get.rvm.io | bash -s stable安装RVM;重新启动你的外壳;使用rvm install 1.9.3 安装 Ruby。 Don'tusesystem Ruby.

标签: ruby-on-rails ruby git macos bundler


【解决方案1】:

以下是在 OSX 上对我有用的方法:

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

gem install mysql -v '2.9.1'

干杯!

【讨论】:

    【解决方案2】:

    欢迎来到 Stack Overflow。

    在我回答你的问题之前,我会推荐anothermh's advice。我一直在使用 rbenv,因为我在一个其他人的团队中工作,但是 rvm 很棒。不要使用 Ruby 的系统安装。如果你坚持使用 Ruby 开发,你会很高兴的。

    也就是说,设置一个非系统的 ruby​​ 环境不足以解决这个问题。首先,您正在查看的mysql gem 版本是旧的,我认为是 2013 年的。它取决于不再支持并且具有多个安全漏洞的 openssl 版本。请不要使用它。

    如果可以,请切换到使用 mysql2 gem。对于大多数 Ruby 和 Rails 项目,mysql2 gem 非常接近于替代品。如果最新版本的 mysql2 gem 仍然无法在您的机器上编译,请参阅 this previous question 以获取有关如何修复它的答案。

    您可能处于不适合您的mysql2 gem 升级的悲惨境地。如果是这种情况,您需要找到 OpenSSL 库的 1.0.x 版本。在您的机器上将旧版本的 OpenSSL 安装到某个路径——我们现在将该路径称为 &lt;openssl_path&gt;。然后您可以将该路径作为参数传递给bundler config,或者您可以像这样直接安装gem:

    gem install mysql -v '2.9.1' -- --with-cflags=\"-I&lt;openssl_path&gt;/include\" --with-ldflags=\"-L&lt;openssl_path&gt;/lib\"

    不过,这仍然会给您带来寻找 OpenSSL 1.0 的问题。我知道有几个人之前发布了仍然通过自制软件安装它的方法,尽管一些托管所需下载以使其工作的存储库不再处于活动状态。自从我上次检查以来,也许有人已经发布了另一个。最近没找到。

    在最坏的情况下,我想你可以去https://www.openssl.org/source/old/ 下载一个旧版本并编译它。同样,我建议您升级到 mysql2 gem,因为这对您来说可能更容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-14
      • 2022-01-20
      • 2017-02-09
      • 2018-09-08
      • 2020-01-16
      • 2021-06-25
      • 2014-01-12
      • 2018-04-05
      相关资源
      最近更新 更多