Skip to content
Latchkey

CMake "CMAKE_CXX_COMPILER not set" in CI

CMake could not determine a C++ compiler when the project enabled the CXX language. The compiler is not installed, not on PATH, or a toolchain file did not set it.

What this error means

Configure aborts complaining CMAKE_CXX_COMPILER is not set after EnableLanguage, usually on a minimal image lacking g++/clang++.

cmake
CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_CXX_COMPILER could be found.
  CMAKE_CXX_COMPILER not set, after EnableLanguage

Common causes

How to fix it

Install a C++ compiler

  1. Install build-essential or g++/clang++ before configuring.
  2. Or point CMake at a specific compiler with -DCMAKE_CXX_COMPILER.
cmake
apt-get install -y build-essential
cmake -S . -B build -DCMAKE_CXX_COMPILER=g++

How to prevent it

  • Bake a C++ toolchain into the runner image and verify g++/clang++ is on PATH before running CMake.

Related guides

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