mysql2:在Homebrew更新后,库未加载:/usr/local/opt/openssl/lib/libssl.1.0.0.dylib。

7

我将mac OS Mojave从v10.14.0升级到v10.14.2以及使用Homebrew安装的所有软件包后,运行bin/rails console时出现以下错误:

/Users/hirurg103/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': dlopen(/Users/hirurg103/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.4/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
  Referenced from: /usr/local/opt/mysql@5.6/lib/libmysqlclient.18.dylib
  Reason: image not found - /Users/hirurg103/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.4/lib/mysql2/mysql2.bundle

我尝试卸载mysql2 gem并使用cpp和ld flags安装它:
gem uninstall mysql2
gem install mysql2 -v 0.4.4 -- --with-cppflags=-I/usr/local/opt/openssl/include/openssl --with-ldflags=-L/usr/local/opt/openssl/lib

但是它并没有起到帮助作用。

同时我尝试将mysql2升级到最新版本(v0.5.3在写这篇文章的时候),但也没有成功。

ls -l /usr/local/opt/openssl/lib给出的结果如下:

total 14472
drwxr-xr-x  4 hirurg103  staff      128 Sep 10 16:13 engines-1.1
-r--r--r--  1 hirurg103  staff  2265596 Dec 13 19:06 libcrypto.1.1.dylib
-r--r--r--  1 hirurg103  staff  3930864 Sep 10 16:13 libcrypto.a
lrwxr-xr-x  1 hirurg103  staff       19 Sep 10 16:13 libcrypto.dylib -> libcrypto.1.1.dylib
-r--r--r--  1 hirurg103  staff   485860 Dec 13 19:06 libssl.1.1.dylib
-r--r--r--  1 hirurg103  staff   720400 Sep 10 16:13 libssl.a
lrwxr-xr-x  1 hirurg103  staff       16 Sep 10 16:13 libssl.dylib -> libssl.1.1.dylib
drwxr-xr-x  5 hirurg103  staff      160 Dec 13 19:06 pkgconfig

我没有看到libssl.1.0.0.dylib,这是mysql2抱怨的。

你遇到过这个错误吗?你能修复它吗?如何修复?

6个回答

13

OpenSSL 1.0 已于2019-12-31到达终止支持期

使用--with-cflags--with-ldflags参数重新安装mysql2 gem,并将其指向openssl@1.1,可以修复该错误:

gem uninstall mysql2
gem install mysql2 -v 0.4.4 -- --with-cflags=\"-I/usr/local/opt/openssl@1.1/include\" --with-ldflags=\"-L/usr/local/opt/openssl@1.1/lib\"

bundle install

最好更新新版本,因为旧版本无法工作。gem install mysql2 -v 0.4.10 -- --with-cflags=\"-I/usr/local/opt/openssl@1.1/include\" --with-ldflags=\"-L/usr/local/opt/openssl@1.1/lib\"我所做的是完全删除版本。gem install mysql2 -- --with-cflags=\"-I/usr/local/opt/openssl@1.1/include\" --with-ldflags=\"-L/usr/local/opt/openssl@1.1/lib\" - isaman kumara

5
我的解决方案是:
brew update
brew upgrade

在尝试下列命令之前,我也试过多次执行brew reinstall openssl 和导出LIBRARY_PATH: export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/。同时,我也通过rbenv重新安装了ruby。
因此,如果运行brew updatebrew upgrade未能消除该错误,请尝试重新安装openssl。如果这还不起作用,请重新安装ruby。

我运行了 brew upgrade,然后为了解决问题,我使用 gem uninstall mysql2; bundle install 进行了重新安装。 - Kevin Cooper

3

对于使用 rbenv 的任何人:

 brew uninstall openssl
 brew install rbenv/tap/openssl@1.0

 gem uninstall mysql2
 gem install mysql2 -- --with-opt-dir="$(brew --prefix rbenv/tap/openssl@1.0)"


注意!只有在安装 Ruby 2.3 或更早版本时才需要这样做。请参阅:https://github.com/rbenv/homebrew-tap - awolfson
这在我的 Ruby 2.5 上有效。谢谢。 - Andree Wille

0

对我来说,更新brew的简单解决方案很有效

  brew update && brew upgrade

我也按照这个指南在这里安装了MacPorts


0

我的解决方案与@Hirurg103非常相似,只是--with-cflag对我不起作用:

gem install mysql2 -v 0.4.10 -- --with-ldflags=\"-L/usr/local/opt/openssl@1.1/lib\"

0
我在我的Intel Mac Monterey上遇到了类似的问题,安装mysql2ruby-3.2.2
brew install openssl@1.1
brew info openssl@1.1

酿造信息将提供一系列的信息。从上面的输出中复制openssl库路径,类似于下面的代码片段。
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"

现在使用上面的库路径安装mysql2 gem。例如。
gem install mysql2 -v 0.5.5 -- --with-openssl-lib="/usr/local/opt/openssl@1.1/lib" 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接