Skip to content

/errors/cmake/no-cmake-c-compiler-could-be-found

CMake Error: No CMAKE_C_COMPILER could be found

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
CMake
exit code
1
versions
CMake 3.x, CMake 4.x
os
any

No CMAKE_C_COMPILER could be found. means CMake's project() command tried to enable the C language and found no working C compiler: none is installed, it is not on PATH, or CC / CMAKE_C_COMPILER points somewhere wrong. Install a compiler (gcc/clang, Xcode command line tools, or Visual Studio Build Tools), or tell CMake where it is with -DCMAKE_C_COMPILER=.... Delete the build directory before trying again, because the failed result is cached. The C++ variant of the message is No CMAKE_CXX_COMPILER could be found.

Reproduce it

CMake 4.4 with Ninja on a machine without a C compiler on PATH:

bash
cat > CMakeLists.txt <<'EOF'
cmake_minimum_required(VERSION 3.20)
project(demo C)
EOF
uv run -q --no-project --python 3.13 --with cmake==4.4.4 --with ninja \
  cmake -G Ninja -S . -B build

Output · exit 1

-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_C_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.

-- Configuring incomplete, errors occurred!

Fixes by platform

SystemInstall a compiler
Debian / Ubuntusudo apt install build-essential
Fedora / RHELsudo dnf install gcc gcc-c++ make
Arch Linuxsudo pacman -S base-devel
Alpine (containers)apk add build-base
macOSxcode-select --install
WindowsVisual Studio or Build Tools with the "Desktop development with C++" workload

On Windows, cl.exe is only on PATH inside a Developer Command Prompt (or after running vcvarsall.bat). Either configure from there, or let a Visual Studio generator find MSVC itself: cmake -G "Visual Studio 17 2022" -S . -B build.

Point CMake at a compiler

bash
rm -rf build
cmake -S . -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
# or through the environment, read only on the first configure
CC=gcc-14 CXX=g++-14 cmake -S . -B build

The compiler is fixed when a build directory is first configured. Changing CC later has no effect until you delete the directory (or CMakeCache.txt), or use cmake --fresh (CMake 3.24 and later).

Projects that need no C compiler

project(name) without LANGUAGES enables C and C++. A C++-only project should say project(app LANGUAGES CXX), and a project that only runs scripts or custom commands can use LANGUAGES NONE:

bash
cat > CMakeLists.txt <<'EOF'
cmake_minimum_required(VERSION 3.20)
project(demo LANGUAGES NONE)
message(STATUS "configured without any compiler")
EOF
uv run -q --no-project --python 3.13 --with cmake==4.4.4 --with ninja \
  cmake -G Ninja -S . -B build | grep -v 'Build files have been written' | sed 's/ ([0-9.]*s)$//'

Output

-- configured without any compiler
-- Configuring done
-- Generating done

Sources