Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

CMake cannot find a C compiler on macOS

ErrorCMake Error: No CMAKE_C_COMPILER could be found.

Short answer

CMake looks for a compiler when project() runs. On a Mac the usual reason is that the Xcode command line tools are not installed. Next in line is a CC variable or -DCMAKE_C_COMPILER that points nowhere, or an old build directory that kept the failure. Fix the first, then configure in a fresh directory.

  • Applies to CMake 4.x, Xcode 26, macOS 26
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out whether any compiler is available to the shell, and which Xcode path is active.

    xcode-select -p
    which cc clang
    echo "CC=$CC"
  2. 2Match what you see, then jump to its fix

    1. 1cc and clang are not found in the shellThe command line tools are not installedFix
    2. 2echo "CC=$CC" prints a path or name you do not recogniseCC or -DCMAKE_C_COMPILER points at a compiler that is not thereFix
    3. 3You fixed the compiler, but the same error returns in the same build folderAn old build directory still holds the earlier compiler choiceFix

What does the error look like?

  • CMake Error: No CMAKE_C_COMPILER could be found.

Cause 1 of 3

The command line tools are not installed

1Check

Apple installs the tools through xcode-select. On a fresh macOS install, running a tool such as git also prompts for them.

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables

2Fix

Install the Command Line Tools package, accept the licence in the dialog, then retry.

xcode-select --install

3Verify

The package info prints a version, and cc is found.

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
which cc

Confirmed by developer.apple.com

Did this fix it?

Cause 2 of 3

CC or -DCMAKE_C_COMPILER points at a compiler that is not there

1Check

CMake reads the CC environment variable when it first configures a build tree. It is ignored if CMAKE_C_COMPILER is already defined, for example with -D on the command line or in a toolchain file.

echo "CC=$CC"
grep CMAKE_C_COMPILER build/CMakeCache.txt

2Fix

Unset CC, drop the -DCMAKE_C_COMPILER option, or give a full path that exists.

unset CC
cmake -S . -B build-clean

3Verify

Configuration reaches the generate step.

cmake -S . -B build-clean

Confirmed by cmake.org

Did this fix it?

Cause 3 of 3

An old build directory still holds the earlier compiler choice

1Check

CMake chooses the compiler the first time a build tree is configured, and the documentation says that once set, the value cannot be changed.

ls build/CMakeCache.txt

2Fix

Configure in a new, empty build directory instead of reusing the old one.

rm -rf build
cmake -S . -B build

3Verify

The configure step prints the C compiler it found.

cmake -S . -B build

Confirmed by cmake.org

Did this fix it?

How do I stop it coming back?

  • Install the command line tools before the first CMake run on a new Mac.
  • Do not export CC in a shell profile unless you want every build to use it.
  • Use a separate build directory per configuration and delete it when the toolchain changes.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Mobile apps

App record creation fails because you lack permission

You cannot add a new app in App Store Connect as a Developer or limited user

Only the Account Holder, an Admin or an App Manager can create an app record, and Apple blocks it until the Account Holder has signed the latest agreement.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.