C++ 使用 Xcode 和 GLFW 找不到 CMAKE_C_COMPILER 的 CMake 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41380900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 15:26:56  来源:igfitidea点击:

CMake error no CMAKE_C_COMPILER could be found using Xcode and GLFW

c++xcodecmake

提问by Jules

I'm trying to follow this tutorial to get started with OpenGL: http://www.learnopengl.com/#!Getting-started/Creating-a-windowand 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:

我正在尝试按照本教程开始使用 OpenGL:http: //www.learnopengl.com/#!Getting-started/Creating-a-window,它需要下载 glfw 和 CMake。我已将下载的 glfw 文件夹设置为源代码文件夹,并在该文件夹中创建了另一个名为“build”的文件夹,然后按照教程的要求将其设置为二进制文件的构建文件夹。我单击“配置”并选择 XCode 作为生成器,因为我使用的是 Mac。问题是当我尝试配置项目时 CMake 给了我这个错误:

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

C 编译器标识是 CMakeLists.txt:3 (project) 中的未知 CMake 错误:找不到 CMAKE_C_COMPILER。

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

配置不完整,出现错误!另请参阅“/Users/standard/Desktop/glfw-3.2.1/build/CMakeFiles/CMakeOutput.log”。

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

另请参阅“/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

我已经读过这个问题,但据我所知,它没有我需要的: CMakeLists.txt:30 (project) 处的 CMake 错误:找不到 CMAKE_C_COMPILER

Thank you.

谢谢你。

回答by hstdt

If you have installed Xcode, try this:

如果您已安装 Xcode,请尝试以下操作:

sudo xcode-select --reset

回答by op414

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

安装 Homebrew 后,Xcode10 / Cmake 3.12 发生在我身上。跑步sudo xcode-select --reset为我修好了。

回答by Cinder Biscuits

Did you install Xcode and Xcode Commandline Tools?

您是否安装了 Xcode 和 Xcode 命令行工具?

xcode-select --install

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

如果您安装了 Xcode Commandline Tools,您应该不会再收到xcrunis missing 错误。

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.

你是如何安装Cmake的?确保安装了 Xcode Commandline Tools 后,请从系统中完全删除 Cmake 并重新安装它。你有一个搞砸了的配置。有很多方法可以在不进行全新安装的情况下调试和修复它,但由于您是新手,这将是最简单、最不令人沮丧的方法。

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

如果您确实安装了 Xcode 命令行工具,则失败,hstdt 建议尝试以下操作:

sudo xcode-select --reset

回答by zeroeth

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:

在新安装的 Xcode 上,命令行工具抱怨同意构建工具不喜欢的 EULA。你可以这样做:

sudo xcodebuild -license

回答by Syntactic Fructose

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:

此错误意味着 CMake 找不到您的标准 C/C++ 编译器,看起来您需要自己导出环境变量。您可以使用以下命令找到 C/C++ 编译器的路径:

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

然后当你有路径时,在 gui 中创建两个变量。如果你从 cline 运行它,它会是这样的

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

回答by Nicholas Frechette

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.

Xcode 10 和旧版本的 CMake 似乎破坏了编译器检测。我知道 CMake 2.2 对我来说坏了,升级到最新的 (2.13) 为我解决了这个问题。它在 Xcode 9 上运行良好,但随着升级而中断。我尝试了其他解决方案(一切都取决于您的情况),但升级 CMake 解决了该问题。

回答by normanius

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

如果我的机器上启用了ccache,我就会得到这个错误。禁用 ccache 为我解决了这个问题。

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

要检查 ccache 是否已启用,请打印系统变量 CC 或 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 .bashrcor .zshrcfile.)

这将打印像下面这样:ccache clang -Qunused-arguments -fcolor-diagnostics。(CC 或 CXX 通常被.bashrc.zshrc文件覆盖。)

To disable ccache, use the following:

要禁用 ccache,请使用以下命令:

CC=clang
CXX=clang++

Then rebuild the cmake project:

然后重建cmake项目:

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.

显然,这是可能的也是使用的CMake的Xcode发生器结合ccache,因为所有被描述这里。但我自己从未尝试过。