skip to Main Content

R Package ‘systemfonts’ Installation Fails in Docker with Missing ft2build.h

Problem

I’m trying to build a Docker image for an R application using r-base:4.3.2 as the base image. The build fails during renv::restore() when trying to install the systemfonts package with the error: fatal error: ft2build.h: No such file or directory.

Dockerfile

# Use r-base as the base image
FROM r-base:4.3.2

RUN apt-get update && apt-get install -y 
    libcurl4-openssl-dev 
    libssl-dev 
    libxml2-dev 
    libfreetype6 
    libfreetype6-dev 
    libharfbuzz-dev 
    libfribidi-dev 
    libpng-dev 
    libtiff5-dev 
    libtiff-dev 
    libjpeg-dev 
    libfontconfig1-dev 
    pandoc 
    curl 
    unzip 
    fonts-liberation 
    fontconfig 
    && apt-get clean 
    && rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /usr/src/app

# Install essential R packages
RUN R -e "install.packages(c('renv'), repos = 'https://cloud.r-project.org')"

# Set up renv
RUN mkdir -p renv/cache
ENV RENV_PATHS_CACHE=/usr/src/app/renv/cache

# Copy renv files
COPY renv.lock .
COPY .Rprofile .
COPY renv/activate.R renv/
COPY renv/settings.dcf renv/

# Restore the R environment
RUN R -e "renv::restore()"

COPY . .

# Download and install AWS CLI
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" 
    && unzip awscliv2.zip 
    && ./aws/install 
    && rm -rf awscliv2.zip aws

RUN aws --version

CMD ["Rscript", "create-dashboard-ecs.R"]

I keep getting this error:

1432.0 - Installing systemfonts ...                    FAILED
1432.3 Error: Error installing package 'systemfonts':
1432.3 =======================================
1432.3
1432.3 * installing *source* package 'systemfonts' ...
1432.3 ** package 'systemfonts' successfully unpacked and MD5 sums checked
1432.3 ** using staged installation
1432.3 Found pkg-config cflags and libs!
1432.3 Using PKG_CFLAGS=
1432.3 Using PKG_LIBS=-lfontconfig -lfreetype
1432.3 ** libs
1432.3 using C++ compiler: 'g++ (Debian 13.2.0-13) 13.2.0'
1432.3 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
1432.3 g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/src/app/renv/staging/1/cpp11/include'     -fPIC  -g -O2 -ffile-prefix-map=/build/reproducible-path/r-base-4.3.2=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -mbranch-protection=standard -Wdate-time -D_FORTIFY_SOURCE=2  -c caches.cpp -o caches.o
1432.3 In file included from caches.h:7,
1432.3                  from caches.cpp:1:
1432.3 ft_cache.h:9:10: fatal error: ft2build.h: No such file or directory
1432.3     9 | #include <ft2build.h>
1432.3       |          ^~~~~~~~~~~~
1432.3 compilation terminated.
1432.3 make: *** [/usr/lib/R/etc/Makeconf:200: caches.o] Error 1
1432.3 ERROR: compilation failed for package 'systemfonts'
1432.3 * removing '/usr/src/app/renv/staging/1/systemfonts'
1432.3 install of package 'systemfonts' failed [error code 1]
1432.3 Traceback (most recent calls last):
1432.3 13: renv::restore()
1432.3 12: renv_restore_run_actions(project, diff, current, lockfile, rebuild)
1432.3 11: renv_install_impl(records)
1432.3 10: renv_install_staged(records)
1432.3  9: renv_install_default(records)
1432.3  8: handler(package, renv_install_package(record))
1432.3  7: renv_install_package(record)
1432.3  6: withCallingHandlers(renv_install_package_impl(record), error = function(e) writef("FAILED"))
1432.3  5: renv_install_package_impl(record)
1432.3  4: r_cmd_install(package, path)
1432.3  3: r_exec_error(package, output, "install", status)
1432.3  2: abort(all)
1432.3  1: stop(fallback)
1432.3 Execution halted

I’ve tried installing libfreetype6 and libfreetype6-dev

What additional system dependencies do I need to install to resolve the missing ft2build.h error and successfully build the systemfonts R package?

It is part of the tidyverse dependency tree in my renv.lock

2

Answers


  1. Chosen as BEST ANSWER

    I was able to fix it by specifying the PKG_CONFIG_PATH

    So adding this line ended up resolving it

    ENV PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig


  2. I got the same question except the error info showed me some tips

    * 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
    Package 'fontconfig', required by 'virtual:world', not found
    Package 'freetype2', required by 'virtual:world', not found
    Using PKG_CFLAGS=
    Using PKG_LIBS=-lfontconfig -lfreetype
    ** libs
    using C++ compiler: ‘x86_64-conda-linux-gnu-c++ (Anaconda gcc) 11.2.0’
    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++17 -I"/home/fangyy/miniconda3/envs/r4.4.1/lib/R/include" -DNDEBUG  -I'/home/fangyy/miniconda3/envs/r4.4.1/lib/R/library/cpp11/include' -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /home/fangyy/miniconda3/envs/r4.4.1/include -I/home/fangyy/miniconda3/envs/r4.4.1/include -Wl,-rpath-link,/home/fangyy/miniconda3/envs/r4.4.1/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 /home/fangyy/miniconda3/envs/r4.4.1/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/r-base-split_1728291269090/work=/usr/local/src/conda/r-base-4.4.1 -fdebug-prefix-map=/home/fangyy/miniconda3/envs/r4.4.1=/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: *** [/home/fangyy/miniconda3/envs/r4.4.1/lib/R/etc/Makeconf:204: caches.o] Error 1
    ERROR: compilation failed for package ‘systemfonts’
    

    As the info said

    Package fontconfig was not found in the pkg-config search path.
    Perhaps you should add the directory containing `fontconfig.pc'
    

    I found the .pc file in my own dir using find /home/fangyy -name fontconfig.pc and added the path to the PKG_CONFIG_PATH

    export PKG_CONFIG_PATH=/home/fangyy/miniconda3/envs/r4.4.1/lib/pkgconfig/
    

    Problem solved

    DONE(systemfont)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search