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 directoryCommon causes
How to fix it
Read CMakeError.log and install the missing piece
- Open CMakeFiles/CMakeError.log to see the exact compiler or linker error.
- 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 buildDrop 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
CMake "could not find CMAKE_ROOT" in CIFix CMake "could not find CMAKE_ROOT" in CI - the cmake binary cannot locate its own module and template dire…
ld "cannot find crtbeginS.o / crt1.o" in CIFix ld "cannot find crtbeginS.o" or "cannot find crt1.o" in CI - the C runtime startup objects are missing be…