如何修复 cargo build 错误:The system library required by crate was not found.

问题

使用 Cargo 构建 Rust 项目时,你可能会遇到如下错误:

cargo_libpcsclite_hint.sh
The system library `libpcsclite` required by crate `pcsc-sys` was not found.
The file `libpcsclite.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
The PKG_CONFIG_PATH environment variable is not set.

解决方案

解决方案在 cargo 输出的错误消息下方。根据你的 Linux 发行版,你需要安装提供 libpcsclite.pc 文件的相应开发包。

cargo_libpcsclite_hint.sh
HINT: if you have installed the library, try setting PKG_CONFIG_PATH to the directory containing `libpcsclite.pc`.

If you are using Debian (or a derivative), try:

    $ sudo apt install pkgconf libpcsclite-dev

If you are using Arch (or a derivative), try:

    $ sudo pacman -S pkgconf pcsclite

If you are using Fedora (or a derivative), try:

    $ sudo dnf install pkgconf pcsc-lite-devel

Check out similar posts by category: Rust