Skip to content
Latchkey

CMake "The C++ compiler ... is not able to compile a simple test program" in CI

During configuration CMake compiles a tiny program to validate the compiler. If that fails it stops with "is not able to compile a simple test program" and points to CMakeError.log for the real reason.

What this error means

Configure aborts at the compiler check. CMakeFiles/CMakeError.log holds the underlying toolchain error, such as a missing linker, missing libc, or a compiler that cannot find its own runtime.

CMake
CMake Error at CMakeLists.txt:2 (project):
  The C++ compiler

    "/usr/bin/c++"

  is not able to compile a simple test program.

  It fails with the following output:
    ...
    /usr/bin/ld: cannot find crt1.o: No such file or directory

Common causes

How to fix it

Read CMakeError.log and install the missing piece

  1. Open CMakeFiles/CMakeError.log to see the exact compiler or linker error.
  2. Install the full toolchain so the test program links, then reconfigure from a clean build dir.
Terminal
cat build/CMakeFiles/CMakeError.log
apt-get update && apt-get install -y build-essential
rm -rf build && cmake -S . -B build

Drop the simple compiler test only when cross compiling

For a freestanding or cross toolchain that cannot link a hosted program, target a static library and skip the check, but only when you know the toolchain is correct.

toolchain.cmake
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

How to prevent it

  • Install a complete toolchain (compiler, linker, libc, startup files) on the runner and always configure into a fresh build directory so a broken cache cannot persist.

Related guides

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