安装R包systemfonts时报错fatal error: ft2build.h: No such file or directory

发布时间 2023-11-12 13:11:11作者: 何帅

安装R包systemfonts时报错fatal error: ft2build.h: No such file or directory

> install.packages("systemfonts")
trying URL 'https://mirrors.e-ducation.cn/CRAN/src/contrib/systemfonts_1.0.5.tar.gz'
Content type 'application/x-gzip' length 80638 bytes (78 KB)
==================================================
downloaded 78 KB

* installing *source* package ‘systemfonts’ ...
** package ‘systemfonts’ successfully unpacked and MD5 sums checked
** using staged installation
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
Package freetype2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `freetype2.pc'
to the PKG_CONFIG_PATH environment variable
No package 'freetype2' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lfontconfig -lfreetype
** libs
rm -f systemfonts.so caches.o cpp11.o dev_metrics.o font_matching.o font_registry.o ft_cache.o string_shape.o font_metrics.o font_fallback.o string_metrics.o emoji.o cache_store.o init.o unix/FontManagerLinux.o
x86_64-conda-linux-gnu-c++ -std=gnu++14 -I"/data/home/heshuai/Miniconda3N/lib/R/include" -DNDEBUG -I'/data/home/heshuai/Miniconda3N/lib/R/library/cpp11/include' -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /data/home/heshuai/Miniconda3N/include -I/data/home/heshuai/Miniconda3N/include -Wl,-rpath-link,/data/home/heshuai/Miniconda3N/lib -fpic -fvisibility-inlines-hidden -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /data/home/heshuai/Miniconda3N/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/r-base-split_1671162973535/work=/usr/local/src/conda/r-base-4.2.2 -fdebug-prefix-map=/data/home/heshuai/Miniconda3N=/usr/local/src/conda-prefix -c caches.cpp -o caches.o
In file included from caches.h:7,
from caches.cpp:1:
ft_cache.h:9:10: fatal error: ft2build.h: No such file or directory
9 | #include <ft2build.h>
| ^~~~~~~~~~~~
compilation terminated.
make: *** [/data/home/heshuai/Miniconda3N/lib/R/etc/Makeconf:178: caches.o] Error 1
ERROR: compilation failed for package ‘systemfonts’
* removing ‘/data/home/heshuai/Miniconda3N/lib/R/library/systemfonts’
* restoring previous ‘/data/home/heshuai/Miniconda3N/lib/R/library/systemfonts’

###--------------------------------------------------------------------

解决方法

经过查找资料,报错原因:最新版本的 fontconfig,但可能缺少相应的 libfontconfig1-dev 包。我的系统为centos7,安装fontconfig-devel 后再重新执行装包的命令,包安装成功。

 yum install fontconfig-devel