CMake cannot find a C compiler on macOS
CMake 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.
Fix it fast
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"2Match what you see, then jump to its fix
- 1
cc and clang are not found in the shellThe command line tools are not installedFix - 2
echo "CC=$CC" prints a path or name you do not recogniseCC or -DCMAKE_C_COMPILER points at a compiler that is not thereFix - 3
You fixed the compiler, but the same error returns in the same build folderAn old build directory still holds the earlier compiler choiceFix
- 1
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_Executables2Fix
Install the Command Line Tools package, accept the licence in the dialog, then retry.
xcode-select --install3Verify
The package info prints a version, and cc is found.
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
which ccConfirmed by developer.apple.com
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.txt2Fix
Unset CC, drop the -DCMAKE_C_COMPILER option, or give a full path that exists.
unset CC
cmake -S . -B build-clean3Verify
Configuration reaches the generate step.
cmake -S . -B build-cleanConfirmed by cmake.org
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.txt2Fix
Configure in a new, empty build directory instead of reusing the old one.
rm -rf build
cmake -S . -B build3Verify
The configure step prints the C compiler it found.
cmake -S . -B buildConfirmed by cmake.org
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
Cannot change the App Privacy answers in App Store Connect
Publish Your App Privacy Responses?
Only the Account Holder, Admin and App Manager roles can answer the App Privacy questions.
2 causes, each with a fixMobile 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 fixMobile apps
You cannot find the button to pull your app back from review
No 'remove this version from review' message appears on the version page
There is no button called Reject Binary.
3 causes, each with a fixMobile apps
Your Apple Account cannot sign in to App Store Connect
Sign-in to App Store Connect is refused for an account that should have access
App Store Connect does not open to every Apple Account.
3 causes, each with a fixMobile apps
Apple rejected the app under Guideline 4.3, Design: Spam
Guideline 4.3(b) - Design - Spam
Guideline 4.3 is Apple's duplicate rule.
5 causes, each with a fixMobile apps
App Store Connect rejects a screenshot because it has transparency
Images can't include alpha channels or transparencies.
App Store Connect does not accept screenshots that carry an alpha channel or transparent pixels.
2 causes, each with a fix