38

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

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
Jules
  • 571
  • 2
  • 5
  • 12
  • Does this answer your question? [The remote system does not have CMake 3.8 or greater](https://stackoverflow.com/questions/72277533/the-remote-system-does-not-have-cmake-3-8-or-greater) – BDisp Dec 17 '22 at 22:24

13 Answers13

137

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

sudo xcode-select --reset
hstdt
  • 5,652
  • 2
  • 34
  • 34
  • 16
    Can you explain this answer? – sam1370 Jul 31 '19 at 00:40
  • 2
    @Sam1370 Command Line Tools for Xcode enables UNIX-style development via Terminal by installing command line developer tools, as well as macOS SDK frameworks and headers. Many useful tools are included, such as the Apple LLVM compiler, linker, and Make. – hstdt Apr 16 '20 at 07:45
  • Thank you! This seemed to work for me, but I also cleaned my build directory, so that may have helped too. – Evan Murray Apr 26 '20 at 10:27
  • 1
    This solved by problem even when having a completely clean build directory would not. – Mark Langen Jun 01 '20 at 20:39
  • Unfortunately does not help for me. – oarfish Feb 16 '23 at 12:26
31

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

op414
  • 582
  • 5
  • 15
28

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
Cinder Biscuits
  • 4,880
  • 31
  • 51
  • I did as you said, and i was able to generate the project! So, thank you. Now I have found a new problem, basically in my build folder I can't find the /lib and /include folders of XCode, as the tuorial instead requires. Plus my formats are different, but i'm guessing it depends on the IDE (the tutorial is using Visual Studio). Do you have any idea about the folders issue? – Jules Jan 02 '17 at 18:29
  • Things work a little differently on Unix-based OS's. There are three places that can be considered /lib and /include: /usr/{lib|include}/ <- Where system libs go /usr/local/{lib|include}/ <- Where "user land" libs go /opt/{lib|include}/ <- Where misc libs go For your purposes, they belong in /usr/local/. This question tells you how to build and install glfw for mac: http://stackoverflow.com/questions/23450334/opengl-3-3-4-1-on-mac-osx-10-9-using-glfw-library – Cinder Biscuits Jan 03 '17 at 00:49
  • 1
    @hstdt your solution helps, post it as an answer – lukas.pukenis Oct 23 '17 at 07:20
  • @hstdt I second that. Your solution got me out of a bind. – Michael Bishop Oct 23 '17 at 15:46
  • After installing the command line tools and running `--reset` I had to reinstall CMake before it would find them. – Tim MB Apr 27 '21 at 14:04
26

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" ...
marcelovca90
  • 2,673
  • 3
  • 27
  • 34
Syntactic Fructose
  • 18,936
  • 23
  • 91
  • 177
  • Running those commands in the Terminal give me this error: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun. Am I doing what you suggested the right way? Sorry, I'm really new to this. – Jules Dec 29 '16 at 14:02
  • I cannot edit for only one character, there is a missing equal after the second -D – Cinn Jan 12 '20 at 22:02
  • 1
    very helpful, work for me ``` cmake -D CMAKE_C_COMPILER="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc" -D CMAKE_CXX_COMPILER="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++" .. ``` – NamNamNam May 30 '20 at 14:18
  • 1
    Nice solution. A clean way to do this in one line is with backticks: " -DCMAKE_C_COMPILER=\`xcrun -find cc\` -DCMAKE_CXX_COMPILER=\`xcrun -find c++\`" . I'm amazed cmake is so broken on mac that it can't do this itself. – user3690202 Dec 18 '20 at 18:58
  • Worked perfectly for me! great solution. And it gets even better with @user3690202 suggestgion – Renato Rodrigues Jan 25 '22 at 17:27
19

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

brew upgrade cmake
Kim T
  • 5,770
  • 1
  • 52
  • 79
14

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
zeroeth
  • 141
  • 1
  • 2
5

For anyone coming to this question nowadays from google, my problem was fixed via

xcodebuild -runFirstLaunch

I found this by inspecting CMakeFiles/CMakeError.log

oarfish
  • 4,116
  • 4
  • 37
  • 66
4

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.

hilsenrat
  • 1,390
  • 2
  • 8
  • 21
1

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.

normanius
  • 8,629
  • 7
  • 53
  • 83
1

I got this error when I had an invalid value set for CMAKE_OSX_SYSROOT. I was trying to give it the name of the SDK e.g. "macOS 10.13". Setting it to the full path of the SDK resolved the issue.

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
Adamski
  • 3,585
  • 5
  • 42
  • 78
0

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

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/...

Rishabh Deep Singh
  • 807
  • 1
  • 12
  • 24
0

after I upgrade Xcode to new verison, I met this error, then I upgrade my cmake version, problem solved.