Skip to content
Latchkey

R "Rcpp" compilation failed in CI

A package built on Rcpp compiled its C++ sources and the compiler exited non-zero, or R could not find a C++ compiler at all. The real error (a missing header, a missing compiler, or a flag) is in the g++ output above the summary.

What this error means

A source build fails during the C++ stage with a g++ error, "fatal error: ... No such file or directory", or R reporting that no C++ compiler is available to build Rcpp-based packages.

R
g++ -std=gnu++17 -I"/usr/share/R/include" -I"/usr/lib/R/site-library/Rcpp/include" ...
RcppExports.cpp:4:10: fatal error: Rcpp.h: No such file or directory
    4 | #include <Rcpp.h>
      |          ^~~~~~~~
compilation terminated.
make: *** [/usr/lib/R/etc/Makeconf:182: RcppExports.o] Error 1
ERROR: compilation failed for package 'mypkg'

Common causes

No C++ compiler or build tooling on the runner

A slim image without build-essential cannot compile the C++ sources, so make fails immediately.

Rcpp headers not installed for the build

Rcpp must be installed so its headers are on the include path; without it, Rcpp.h is not found.

How to fix it

Install a compiler and Rcpp before building

  1. Install build-essential so g++ and make are present.
  2. Install Rcpp so its headers are available to dependents.
  3. Re-run the build of the C++ package.
Terminal
sudo apt-get install -y build-essential
Rscript -e 'install.packages("Rcpp", repos="https://cloud.r-project.org")'

Install a precompiled binary instead

Use a binary repo so the Rcpp-based package is fetched prebuilt and never compiled in CI.

Terminal
Rscript -e 'install.packages("mypkg", repos="https://packagemanager.posit.co/cran/__linux__/jammy/latest")'

How to prevent it

  • Install build-essential before any source build.
  • Prefer binary package repos so C++ code is not compiled in CI.
  • Cache the R library so compiled packages are reused.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →