如何链接从 Homebrew 安装的 mysql-client 与柴油 cli?

bee*_*oop 1 mysql macos linker-errors rust

我一直在尝试使用 安装 Rust Diesel CLI 工具cargo install diesel_cli,但安装失败并出现链接错误

ld: library not found for -lmysqlclient
 clang: error: linker command failed with exit code 1 
(use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

我安装使用自制的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”
Run Code Online (Sandbox Code Playgroud)

PATH在警告消息中设置了和 标志,但在尝试安装diesel-cli工具时仍然出现上述链接错误。我不熟悉如何在 Rust 中进行链接 - 我需要在这里执行额外的步骤来直接链接 mysqlclient 吗?

小智 9

Cargo 忽略LDFLAGSand CPPFLAGS,你应该设置RUSTFLAGS。类似这个未经测试的调用:

RUSTFLAGS="-L/your_lib -I/your_include" cargo install diesel_cli
Run Code Online (Sandbox Code Playgroud)

相关文件