如何使用 diesel-cli 从 Homebrew 安装 link mysql-client?
How to link mysql-client installed from Homebrew with diesel-cli?
我一直在尝试使用 cargo install diesel_cli
安装 Rust Diesel CLI 工具,但安装失败并出现 linking 错误
ld: library not found for -lmysqlclient
clang: error: linker command failed with exit code 1
(use -v to see invocation)
我使用 Homebrew 安装了 MySQL 客户端:brew install mysql-client
。在安装过程中,我收到以下警告:
mysql-client is keg-only, which means it was not symlinked into /usr/local,
because conflicts with mysql.
If you need to have mysql-client first in your PATH run:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
For compilers to find mysql-client you may need to set:
export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
export CPPFLAGS="-I/usr/local/opt/mysql-client/include”
我设置了 PATH
和警告消息中的标志,但在尝试安装 diesel-cli 工具时仍然出现上述 linking 错误。我不熟悉如何在 Rust 中执行 linking - 我需要在这里直接执行 link mysqlclient 的额外步骤吗?
Cargo 忽略 LDFLAGS
和 CPPFLAGS
,您应该改为设置 RUSTFLAGS
。像这样未经测试的调用:
RUSTFLAGS="-L/your_lib -I/your_include" cargo install diesel_cli
在我这边,我并没有让它只与 mysql-client 一起工作。我必须安装 mysql 和
brew install mysql
最后,重要的是你有一个版本的mysql客户端动态库。
这里安装地雷:
/usr/local/lib/libmysqlclient.21.dylib
/usr/local/Cellar/mysql/8.0.15/lib/libmysqlclient.21.dylib
成功了。
我一直在尝试使用 cargo install diesel_cli
安装 Rust Diesel CLI 工具,但安装失败并出现 linking 错误
ld: library not found for -lmysqlclient
clang: error: linker command failed with exit code 1
(use -v to see invocation)
我使用 Homebrew 安装了 MySQL 客户端:brew install mysql-client
。在安装过程中,我收到以下警告:
mysql-client is keg-only, which means it was not symlinked into /usr/local,
because conflicts with mysql.
If you need to have mysql-client first in your PATH run:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
For compilers to find mysql-client you may need to set:
export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
export CPPFLAGS="-I/usr/local/opt/mysql-client/include”
我设置了 PATH
和警告消息中的标志,但在尝试安装 diesel-cli 工具时仍然出现上述 linking 错误。我不熟悉如何在 Rust 中执行 linking - 我需要在这里直接执行 link mysqlclient 的额外步骤吗?
Cargo 忽略 LDFLAGS
和 CPPFLAGS
,您应该改为设置 RUSTFLAGS
。像这样未经测试的调用:
RUSTFLAGS="-L/your_lib -I/your_include" cargo install diesel_cli
在我这边,我并没有让它只与 mysql-client 一起工作。我必须安装 mysql 和
brew install mysql
最后,重要的是你有一个版本的mysql客户端动态库。
这里安装地雷:
/usr/local/lib/libmysqlclient.21.dylib
/usr/local/Cellar/mysql/8.0.15/lib/libmysqlclient.21.dylib
成功了。