28
votes

I'm trying to follow this tutorial to get started with OpenGL: http://www.learnopengl.com/#!Getting-started/Creating-a-window and it requires downloading glfw and CMake. I have set the downloaded glfw folder as the source code folder and I have created inside that folder another one called "build" which I then set as the build one for the binaries, as the tutorial asks. I click on "Configure" and I select XCode as the Generator, since I'm on a Mac. The problem is that when I try to configure the project CMake gives me this error:

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

Configuring incomplete, errors occurred! See also "/Users/standard/Desktop/glfw-3.2.1/build/CMakeFiles/CMakeOutput.log".

See also "/Users/standard/Desktop/glfw-3.2.1/build/CMakeFiles/CMakeError.log".

I've already read this question, but as far as I can understand, it doesn't have what I need: CMake Error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found

Thank you.

10

10 Answers

96
votes

If you have installed Xcode or Command Line Tools for Xcode, try this:

sudo xcode-select --reset
28
votes

This happened to me with Xcode10 / Cmake 3.12 after installing Homebrew. Running sudo xcode-select --reset fixed it for me.

23
votes

Did you install Xcode and Xcode Commandline Tools?

xcode-select --install

If you have Xcode Commandline Tools installed, you should no longer be receiving the xcrun is missing error.

How did you install Cmake? Once you have ensured that Xcode Commandline Tools is installed, please completely remove Cmake from your system and reinstall it. You have a screwed up configuration. There are ways to debug and fix it without a clean install, but since you are new to this, it will be the easiest and lest frustrating way.

Failing that if you do have Xcode Commandline Tools installed, hstdt suggested trying this:

sudo xcode-select --reset
18
votes

This error means CMake cannot find your standard C/C++ Compiler, looks like you'll need to export the environment variables yourself. you can find the path of your C/C++ compiler with:

xcrun -find c++
xcrun -find cc

Then afterwards when you have the paths, create two variables inside the gui. If you are running it from the cline, it would be something like

cmake -D CMAKE_C_COMPILER="/path/to/your/c/compiler/executable" -D CMAKE_CXX_COMPILER="/path/to/your/cpp/compiler/executable" ...
13
votes

On a fresh Xcode install the command line tools complain about agreeing to the EULA which build tools don't like. Which you can do with:

sudo xcodebuild -license
7
votes

If you are on a Mac computer and have Homebrew, you can simply upgrade cmake, forcing the compiler to be reconfigured:

brew upgrade cmake
2
votes

In my case, I needed to install CMake from CMake official site, download the .dmg, install it and then add the CMake folder the system's PATH.

Before the installation, the output of which cmake is /usr/local/bin/cmake.
After the installation it should be something like /Applications/CMake.app/Contents/bin/cmake.

This has solved the issue for me.

0
votes

Compiler detection appears to be broken with Xcode 10 and older versions of CMake. I know that it broke for me with CMake 2.2 and upgrading to the latest (2.13) solved it for me. It was working fine with Xcode 9 and it broke with the upgrade. I tried the other solutions (all good depending on your situation) but upgrading CMake fixed the issue.

0
votes

I get exactly this error if ccache is enabled on my machine. Disabling ccache fixed the problem for me.

To check if ccache is enabled, print the systems variables CC or CXX:

echo $CC
echo $CXX

This prints something like the following: ccache clang -Qunused-arguments -fcolor-diagnostics. (CC or CXX are typically overridden by the .bashrc or .zshrc file.)

To disable ccache, use the following:

CC=clang
CXX=clang++

Then rebuild the cmake project:

cmake -G Xcode <path/to/CMakeLists.txt>

Apparently, it is possible to use CMake's Xcode generator also in combination with ccache, as is described here. But I never tried it out myself.

0
votes

If you are on CLion and facing this issue try changing the C and C++ compiler location inside Toolchains settings to the latest one. the default GCC installation directory is /usr/local/Cellar/gcc/...