5

如何在 M1 mac 上安装 MySQL2 Gem

 8 months ago
source link: https://www.ixiqin.com/2023/12/27/how-to-install-mysql-2-gem-on-m1-mac/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
如何在 M1 mac 上安装 MySQL2 Gem

如何在 M1 mac 上安装 MySQL2 Gem

在 M1 的 mac 上安装 mysql2 这个 gem 的时候,经常会遇到如下的报错:

1 warning generated.
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: warning: -multiply_defined is obsolete
ld: warning: ignoring duplicate libraries: '-lruby.3.2'
<strong>ld: library 'zstd' not found
</strong>clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

根据提示,我们可以看到是 zstd 这个依赖找不到导致的编译失败。这是因为 mysql2 是一个 Native Gem,依赖了大量的系统组件,如果我们没有对应的系统组件,就无法找到。

但实际上在我的系统中已经安装了 zstd,只是在 mysql2 的构建过程中找不到。

d2b5ca33bd970f64a6301fa75ae2eb22-3.png!pic

要解决这个问题有几个思路:

  1. 在构建时能找到 zstd ;
  2. 在构建时指定 zstd 的位置。

这里我选择第二种方式:

gem install mysql2 -- --with-mysql-config=$(brew --prefix mysql)/bin/mysql_config --with-ldflags="-L$(brew --prefix zstd)/lib -L$(brew --prefix openssl)/lib" --with-cppflags=-I$(brew --prefix openssl)/include

通过 -- -with-mysql-config 的方式,可以在安装时指定构建的参数,从而实现让 gem 构建时使用我们设置的路径,从而完成 gem 的安装。

d2b5ca33bd970f64a6301fa75ae2eb22-4-1024x250.png!pic

本条目发布于2023年12月27日。属于Ruby On Rails分类,被贴了 随笔 标签。 ← 一些适合送给小朋友的礼品

发表回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

评论 *

显示名称 *

电子邮箱地址 *

网站地址

在此浏览器中保存我的显示名称、邮箱地址和网站地址,以便下次评论时使用。

如果有人回复我的评论,请通过电子邮件通知我。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK