CMake 找不到 Visual C++ 编译器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31619296/
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 14:00:18  来源:igfitidea点击:

CMake does not find Visual C++ compiler

c++cmakevisual-studio-2015

提问by Asher

After installing Visual Studio 2015 and running CMake on a previous project, CMake errors stating that it could not find the C compiler.

安装 Visual Studio 2015 并在以前的项目上运行 CMake 后,CMake 错误指出它找不到 C 编译器。

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

CMake Error at CMakeLists.txt:4 (PROJECT):
  No CMAKE_CXX_COMPILER could be found.

I went searching for cl.exein the Visual Studio folder,C:\Program Files\Microsoft Visual Studio 14.0, and could not find it.

cl.exe在 Visual Studio 文件夹中搜索,C:\Program Files\Microsoft Visual Studio 14.0但找不到。

How do I set up CMake to work on Windows with Visual Studio 2015?

如何使用 Visual Studio 2015 设置 CMake 以在 Windows 上工作?

回答by Asher

I have found the solution. While the Visual Studio IDE installed successfully it did not install any build tools and therefore did not install the C++ compiler.

我找到了解决办法。虽然 Visual Studio IDE 安装成功,但它没有安装任何构建工具,因此没有安装 C++ 编译器。

By attempting to manually create a C++ project in the Visual Studio 2015 GUII was able to prompt it to download the C++ packages. CMake was then able to find the compiler without any difficulty.

通过尝试在 Visual Studio 2015 GUI 中手动创建 C++ 项目,我能够提示它下载 C++ 包。然后 CMake 能够毫无困难地找到编译器。

回答by Fortune

Here is the solution that worked for me:

这是对我有用的解决方案:

  1. Open Visual Studio command prompt tool (as an administrator). On windows 10 it might be called 'Developer command prompt'.
  2. Navigate to where you have the CMake executable
  3. Run Cmake.exe
  4. Proceed as usual to select build and source folder
  5. Select the appropriate Visual Studio compiler and hit the configure button
  1. 打开 Visual Studio 命令提示工具(以管理员身份)。在 Windows 10 上,它可能被称为“开发人员命令提示符”。
  2. 导航到您拥有 CMake 可执行文件的位置
  3. 运行 Cmake.exe
  4. 像往常一样继续选择构建和源文件夹
  5. 选择合适的 Visual Studio 编译器并点击配置按钮

Hopefully it should run without problems.

希望它应该运行没有问题。

回答by Carl Walsh

I looked in CMakeError.log file and found an error about cannot run 'rc.exe'

我查看了 CMakeError.log 文件,发现了一个关于 cannot run 'rc.exe'

I searched and found this answerto copy RC.Exe and RcDll.Dll from the Microsoft SDKs bin to the VC bin, and then CMake worked.

我搜索并找到了这个答案,将 RC.Exe 和 RcDll.Dll 从 Microsoft SDKs bin 复制到 VC bin,然后 CMake 工作。



Edit: The top answer to another questionsuggests that it's a PATH issue, so it could be enough to ensure the Microsoft SDK bin is in your PATH.

编辑:另一个问题的最佳答案表明这是一个 PATH 问题,因此足以确保 Microsoft SDK bin 在您的 PATH 中。

回答by Hrushikesh Kulkarni

Make sure you are using the correct version of Visual Studio in the generator. I had incorrectly selected Visual Studio 15 when Visual Studio 14 installed.

确保在生成器中使用正确版本的 Visual Studio。安装 Visual Studio 14 时,我错误地选择了 Visual Studio 15。

回答by Vadim Berman

Those stumbling with this on Visual Studio 2017: there is a feature related to CMake that needs to be selected and installed together with the relevant compiler toolsets. See the screenshot below.

那些在 Visual Studio 2017 上遇到这个问题的人:有一个与 CMake 相关的功能需要与相关的编译器工具集一起选择和安装。请参阅下面的屏幕截图。

Visaul C++ tools for CMake must be installed

必须安装用于 CMake 的 Visaul C++ 工具

回答by TrophyGeek

If none of the above solutions worked, then stop and do a sanity check.

如果上述解决方案均无效,请停止并进行完整性检查。

I got burned using the wrong -G <config>string and it gave me this misleading error.

我使用错误的-G <config>字符串被烧毁,它给了我这个误导性错误。

First, run from the VS Command Prompt notthe regular command prompt. You can find it in Start Menu -> Visual Studio 2015 -> MSBuild Command Prompt for VS2015This sets up all the correct paths to VS tools, etc.

首先,从 VS 命令提示符而不是常规命令提示符运行。您可以在Start Menu -> Visual Studio 2015 -> MSBuild Command Prompt for VS2015This set up all正确的路径到VS工具等中找到它 。

Now see what generators are available from cmake...

现在看看 cmake 有哪些可用的生成器...

cmake -help

cmake -help

...<snip>... The following generators are available on this platform: Visual Studio 15 [arch] = Generates Visual Studio 15 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files. Optional [arch] can be "Win64" or "IA64". ...

...<snip>... The following generators are available on this platform: Visual Studio 15 [arch] = Generates Visual Studio 15 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files. Optional [arch] can be "Win64" or "IA64". ...

Then chose the appropriate string withthe [arch] added.

然后选择适当的字符串所述[拱]加入。

mkdir _build cd _build cmake .. -G "Visual Studio 15 Win64"

mkdir _build cd _build cmake .. -G "Visual Studio 15 Win64"

Running cmake in a subdirectory makes it easier to do a 'clean' since you can just delete everything in that directory.

在子目录中运行 cmake 可以更轻松地进行“清理”,因为您可以删除该目录中的所有内容。

I upgraded to Visual Studio 15 but wasn't paying attention and was trying to generate for 2012.

我升级到 Visual Studio 15 但没有注意并试图为 2012 生成。

回答by chowey

For me, I checked the CMakeError.logfile and found:

对我来说,我检查了CMakeError.log文件,发现:

[...] error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution".

[...] 错误 MSB8036:未找到 Windows SDK 8.1 版。安装所需版本的 Windows SDK 或更改项目属性页中的 SDK 版本,或通过右键单击解决方案并选择“重定向解决方案”。

This is despite using Visual Studio 2017 on Windows 7. So it appears that CMake is trying to build its detection project with the Windows 8.1 SDK.

尽管在 Windows 7 上使用了 Visual Studio 2017。所以看起来 CMake 正在尝试使用 Windows 8.1 SDK 构建其检测项目。

I used the Visual Studio installer to add that component and now CMake is happy as a clam.

我使用 Visual Studio 安装程序添加了该组件,现在 CMake 很高兴。

回答by Alen Wesker

Menu → Visual Studio 2015 → MSBuild Command Prompt for Visual Studio 2015. Then CMake can find cl.exe.

菜单 → Visual Studio 2015 → Visual Studio 2015 的 MSBuild 命令提示符。然后 CMake 可以找到cl.exe.

set PATH="c:\Program Files (x86)\Windows Kits\bin.0.16299.0\x64\";%PATH%

Change the upper path to where your Windows SDK is installed.

将上面的路径更改为安装 Windows SDK 的位置。

CMake can find rc.exe.

CMake 可以找到rc.exe.

cd to the path of CMakeLists.txtand do:

cd 到路径CMakeLists.txt并执行:

md .build
cd .build
cmake .. -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=Release
cmake --build .

The param after -Gshould be fetched by CMake. Use --help; you may or may not have the generator.

后面的参数-G应该由 CMake 获取。使用--help; 您可能有也可能没有发电机。

回答by Philippe Ferdinand

I ran into the same issue and fixed it by relaunching the Visual Studio Install and checking the following option:

我遇到了同样的问题,并通过重新启动 Visual Studio 安装并检查以下选项来修复它:

Windows and Web Development/ Universal Windows App Development Tools/ Windows 10 SDK

Windows and Web Development/ Universal Windows App Development Tools/Windows 10 SDK

It contains the standard C++ headers used in most applications and therefore it is often necessary to install it as well.

它包含大多数应用程序中使用的标准 C++ 头文件,因此通常也需要安装它。

回答by Lars Bilke

If you are on Visual Studio 2017 you need at least CMake 3.8!

如果您使用的是 Visual Studio 2017,则至少需要 CMake 3.8!