我正在尝试在 fedora 上的 rustup 环境中构建一个依赖于 libudev 的 rust 应用程序。目前,我在尝试使用以下命令编译应用程序时收到错误cargo build --release
:
error: failed to run custom build command for `libudev-sys v0.1.4`
Caused by:
process didn't exit successfully: `/home/me/myApp/target/release/build/libudev-sys-7d615f10fc24f9b2/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=LIBUDEV_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=LIBUDEV_STATIC
cargo:rerun-if-env-changed=LIBUDEV_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
--- stderr
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "`\"pkg-config\" \"--libs\" \"--cflags\" \"libudev\"` did not exit successfully: exit status: 1\n--- stderr\nPackage libudev was not found in the pkg-config search path.\nPerhaps you should add the directory containing `libudev.pc'\nto the PKG_CONFIG_PATH environment variable\nPackage 'libudev', required by 'virtual:world', not found\n"', /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/libudev-sys-0.1.4/build.rs:38:41
过去,在 ubuntu(或任何基于 debian 的系统,使用系统 rust install 而不是 rustup)上执行上述操作后,一切运行良好sudo apt install libudev1 && sudo apt install libudev-dev
。
到目前为止,我已经尝试或考虑过:
看看建议无法找到 Libudev.pc,大多数建议都是针对某人的 homebrew / linuxbrew 设置,而这个问题是针对安装了 Rustup 的 rust 环境的 Fedora。
尝试更新我的内容
PKG_CONFIG_PATH
并检查内容PKG_CONFIG
,特别是:- 通过 来查看库的位置
yum provides */libudev.pc
,这会显示Filename : /usr/lib/pkgconfig/libudev.pc
&Filename : /usr/lib64/pkgconfig/libudev.pc
- 将 lib 文件夹添加到
PKG_CONFIG_PATH
my 中.bashrc
:PKG_CONFIG_PATH=$PATH:/usr/lib/pkgconfig/:/usr/lib64/pkgconfig
- 启动一个新的shell,运行
pkg-config --libs --cflags libudev
,仍然报错Package libudev was not found in the pkg-config search path. Perhaps you should add the directory containing `libudev.pc' to the PKG_CONFIG_PATH environment variable Package 'libudev', required by 'virtual:world', not found
- 跑步
pkg-config --variable pc_path pkg-config
节目/usr/lib64/pkgconfig:/usr/share/pkgconfig
- 通过 来查看库的位置
考虑过这样做
sudo dnf install libudev
,但犹豫了,因为我使用的是 rustup 环境,并且安装它也会触发安装 fedora 系统版本的 rust。
答案1
这样做sudo dnf install rust-libudev-devel
可以解决这个问题,但我个人对这个答案并不满意,因为这样做还需要冗余安装 rust (fedora 包)。
答案2
这样做sudo dnf install libudev-devel
(实际上安装了systemd-devel
,至少在 Fedora 37 上)解决了这个问题,而无需多余地安装cargo
和rust
以及一堆其他 Fedora(而不是rustup
)软件包。