微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在 Bigsur 上安装 mysql2 Gem

如何解决无法在 Bigsur 上安装 mysql2 Gem

我使用的是 ruby​​ 3.0.1p64 并使用 macOS bigsur 11.04 MysqL 安装并运行

捆绑安装要求我安装 MysqL2

我正在尝试像这样安装 MysqL2 gem:

sudo gem install MysqL2 -v '0.5.3' --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: /Users/henri/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/MysqL2-0.5.3/ext/MysqL2
/Users/henri/.rbenv/versions/3.0.1/bin/ruby -I /Users/henri/.rbenv/versions/3.0.1/lib/ruby/3.0.0 -r ./siteconf20210617-53969-y4phap.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
*** 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.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdier
    --ruby=/Users/henri/.rbenv/versions/3.0.1/bin/$(RUBY_BASE_NAME)
    --with-MysqL-dir
    --without-MysqL-dir
    --with-MysqL-include
    --without-MysqL-include=${MysqL-dir}/include
    --with-MysqL-lib
    --without-MysqL-lib=${MysqL-dir}/lib
    --with-MysqL-config
    --without-MysqL-config
    --with-MysqLclient-dir
    --without-MysqLclient-dir
    --with-MysqLclient-include
    --without-MysqLclient-include=${MysqLclient-dir}/include
    --with-MysqLclient-lib
    --without-MysqLclient-lib=${MysqLclient-dir}/lib
    --with-MysqLclientlib
    --without-MysqLclientlib
/Users/henri/.rbenv/versions/3.0.1/lib/ruby/3.0.0/mkmf.rb:1050:in `block in find_library': undefined method `split' for nil:NilClass (NoMethodError)
    from /Users/henri/.rbenv/versions/3.0.1/lib/ruby/3.0.0/mkmf.rb:1050:in `collect'
    from /Users/henri/.rbenv/versions/3.0.1/lib/ruby/3.0.0/mkmf.rb:1050:in `find_library'
    from extconf.rb:87:in `<main>'

To see why this extension Failed to compile,please check the mkmf.log which can be found here:

  /Users/henri/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/extensions/arm64-darwin-20/3.0.0/MysqL2-0.5.3/mkmf.log

extconf Failed,exit code 1

我的 mkmf.log 看起来像这样:

    --------------------

have_func: checking for rb_wait_for_single_fd()... -------------------- yes

"clang -fdeclspec -o conftest -I/Users/henriknafo/.rbenv/versions/3.0.1/include/ru$
conftest.c:14:57: error: use of undeclared identifier 'rb_wait_for_single_fd'
int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_wait_for_single_fd; ret$
                                                        ^
1 error generated.
checked program was:
/* begin */
 1: #include "ruby.h"
 2:
 3: /*toP*/
 4: extern int t(void);
 5: int main(int argc,char **argv)
 6: {
 7:   if (argc > 1000000) {
 8:     int (* volatile tp)(void)=(int (*)(void))&t;
 9:     printf("%d",(*tp)());
10:   }
11:
12:   return !!argv[argc];
13: }
14: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_wait_for_single_fd;$
/* end */

这会不会与 ruby​​ 3.0.1 不兼容? 我应该安装什么库以便 MysqL2 gem 安装

有人有建议吗?

解决方法

这对我有用:

brew install openssl

酿造链接mysql

,
  1. 检查是否安装了 openssl。
  2. 如果没有安装,请安装它。 brew install openssl
  3. 链接它。 brew link openssl

你会得到这样的东西。

 ➜ brew link openssl
Warning: Refusing to link macOS provided/shadowed software: openssl@1.1
If you need to have openssl@1.1 first in your PATH,run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
  1. 复制
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

  export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

然后运行它。

  1. 再次bundle install

它适用于我的项目。

更新:

  1. export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
  2. bundle install

可能有用。

,

你可能需要 libmysqlclient-dev 查看 https://stackoverflow.com/a/53081763/7205276 线程

上的最后一条评论 (Error installing mysql2: ERROR: Failed to build gem native extension) ,

我在 bundle install 之前安装了 mysql2 并在安装之前删除了名为 .bundle 的文件夹:

gem install mysql2 -v '0.5.3' -- \
 --with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.25_1/lib \
 --with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.25_1 \
 --with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.25_1/bin/mysql_config \
 --with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.25_1/include

现在我很好。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。