You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu系统下Rust编译yeslogic-fontconfig-sys失败求助

Ubuntu环境下Rust项目依赖yeslogic-fontconfig-sys编译失败的解决方案

问题现象

在Ubuntu系统中开发Rust项目时,所有依赖yeslogic-fontconfig-sys crate的项目(比如使用plotters库,或者执行cargo install inlyne)均无法编译构建。

例如构建含plotters依赖的项目时,执行cargo build会报错:

>> cargo build
   Compiling yeslogic-fontconfig-sys v3.2.0
   Compiling png v0.17.9
   Compiling serde v1.0.171
   Compiling num-rational v0.4.1
error: failed to run custom build command for `yeslogic-fontconfig-sys v3.2.0`

Caused by:
  process didn't exit successfully: `pathTo/Projectrust_bench/target/debug/build/yeslogic-fontconfig-sys-aadd5f5fe0e3d3ca/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=RUST_FONTCONFIG_DLOPEN
  cargo:rerun-if-env-changed=FONTCONFIG_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=FONTCONFIG_STATIC
  cargo:rerun-if-env-changed=FONTCONFIG_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_ALLOW_SYSTEM_CFLAGS=\"1\" PKG_CONFIG_ALLOW_SYSTEM_LIBS=\"1\" \"pkg-config\" \"--libs\" \"--cflags\" \"fontconfig\"` did not exit successfully: exit status: 1\nerror: could not find system library 'fontconfig' required by the 'yeslogic-fontconfig-sys' crate\n\n--- stderr\nPackage fontconfig was not found in the pkg-config search path.\nPerhaps you should add the directory containing `fontconfig.pc'\nto the PKG_CONFIG_PATH environment variable\nNo package 'fontconfig' found\n"', /home/metamorph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/yeslogic-fontconfig-sys-3.2.0/build.rs:8:48
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

已尝试安装依赖:

sudo apt install libfontconfig1-dev pkg-config fontconfig libfontconfig-dev

但问题依旧,执行pkg-config --variable=libdir fontconfig仍提示:

>> pkg-config --variable=libdir fontconfig
Package fontconfig was not found in the pkg-config search path.
Perhaps you should add the directory containing `fontconfig.pc'
to the PKG_CONFIG_PATH environment variable
No package 'fontconfig' found

解决步骤

1. 确认fontconfig.pc文件位置

先查找系统中是否存在fontconfig.pc文件:

sudo find / -name "fontconfig.pc"

通常该文件会位于/usr/lib/x86_64-linux-gnu/pkgconfig/或/usr/share/pkgconfig/目录下。

2. 配置PKG_CONFIG_PATH环境变量

如果找到fontconfig.pc的路径(比如/usr/lib/x86_64-linux-gnu/pkgconfig/),临时设置环境变量:

export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig/:$PKG_CONFIG_PATH"

然后重新执行pkg-config --variable=libdir fontconfig验证是否能找到包。

若要永久生效,将上述命令添加到~/.bashrc或~/.zshrc文件末尾,再执行:

source ~/.bashrc
# 若使用zsh则执行
source ~/.zshrc

3. 彻底重装fontconfig开发包

如果上述方法无效,尝试彻底卸载并重装:

sudo apt purge libfontconfig1-dev fontconfig pkg-config
sudo apt autoremove
sudo apt install libfontconfig1-dev pkg-config fontconfig

4. 强制使用内置fontconfig库

如果系统依赖始终无法正常识别,可通过环境变量强制yeslogic-fontconfig-sys使用其内置的fontconfig库,无需依赖系统库:

export RUST_FONTCONFIG_DLOPEN=1

或者在执行cargo命令时临时设置:

RUST_FONTCONFIG_DLOPEN=1 cargo build
# 安装inlyne时同理
RUST_FONTCONFIG_DLOPEN=1 cargo install inlyne

若需永久生效,将export RUST_FONTCONFIG_DLOPEN=1添加到~/.bashrc或~/.zshrc中即可。


内容的提问来源于stack exchange,提问作者Michael

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 09:53:13