简体   繁体   中英

CMake error no CMAKE_C_COMPILER could be found using Xcode and GLFW

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.

如果您已经Command Line Tools for Xcode安装了XcodeCommand Line Tools for Xcode ,请尝试以下操作:

sudo xcode-select --reset

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

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

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

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

如果你在 Mac 电脑上并且有 Homebrew,你可以简单地升级 cmake,强制重新配置编译器:

brew upgrade cmake

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.

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.

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.

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

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 eg "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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM