使用CMake为VS 2017生成解决方案时出现问题 [英] Problems generating solution for VS 2017 with CMake

查看:440
本文介绍了使用CMake为VS 2017生成解决方案时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我昨天安装了Visual Studio 2017.我还安装了支持VS 2017的CMake 3.7.2.

So I installed Visual Studio 2017 yesterday. I also installed CMake 3.7.2 which supports VS 2017.

我的VS安装使用Game development with C++工作流程和一些其他组件:

My VS installation is with the Game development with C++ workflow + a few other components:

我还添加了CMake的内容(但我认为我什至不需要它-因为我将CMake用作生成VS解决方案的独立工具)和MSBuild(甚至在以前我就使用msbuild.exe添加该组件-因此不确定该附加组件的功能是什么.

I've also added the CMake stuff (but I don't think I even needed it - since I'm using CMake as a standalone tool to just generate the VS solutions) and MSBuild (I had msbuild.exe even before adding that component - so not sure what exactly does that additional component do).

使用VS 2015,我可以从常规命令提示符下运行cmake .以获得解决方案.

With VS 2015 I was able to just run cmake . from a normal command prompt for a solution.

在VS 2017中,工作流程发生了变化-我已阅读

With VS 2017 the workflow changes - I've read this post from Microsoft.

所以我尝试了以下操作:

So I tried the following:

  • 我打开了Developer Command Prompt for VS 2017,然后从中运行了cmake . -G "NMake Makefiles".然后运行cmake --build .可以正确编译所有内容.
  • 当我在提示符下尝试以下操作:cmake . -G "Visual Studio 15 2017 Win64"强制创建解决方案时,出现以下错误:

  • I opened the Developer Command Prompt for VS 2017 and from it I ran cmake . -G "NMake Makefiles". Then running cmake --build . compiled everything properly.
  • When I tried the following in the prompt: cmake . -G "Visual Studio 15 2017 Win64" to force the creation of a solution I got the following errors:

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
  No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:3 (project):
  No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!

我还尝试使用 vswhere.exe 设置环境,并像这样运行vcvarsall.bat:

I also tried setting up the environment using vswhere.exe and running vcvarsall.bat like this:

"C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Community \ VC \ Auxiliary \ Build \ vcvarsall.bat" amd64

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64

同样,我只能生成NMake文件,而不能生成解决方案.

and again I could only generate NMake files and not a solution.

那我该如何解决?

为什么cl.exeVC\Tools\MSVC\14.10.25017\bin中时会报告Version 19.10.25017?

推荐答案

将我的评论变成答案

错误-- The CXX compiler identification is unknown - No CMAKE_CXX_COMPILER could be found.基本上意味着CMake无法编译简单的测试程序(它始终是识别/验证编译器的一部分).

The error -- The CXX compiler identification is unknown - No CMAKE_CXX_COMPILER could be found. basically means that CMake wasn't able to compile a simple test program (which it always does as part of identifying/validating the compiler).

您可以查看CMakeFiles\CMakeError.log(相对于二进制输出目录),错误原因应该在其中.

You can take a look into CMakeFiles\CMakeError.log (relative to your binary output directory), the error reason should be in there.

到目前为止,我遇到的两个可能原因:

Two possible reasons I came across so far:

  1. 缺少管理员权限.您可以尝试从具有管理权限的shell再次运行此程序,以交叉检查是否已将Visual Studio设置为需要管理员权限.

  1. Missing administrator rights. You can try running this again from a shell that has administrative rights to crosscheck if your Visual Studio was setup with the need for administrator rights.

缺少Windows SDK.验证您的SDK安装,例如检查您是否安装了任何资源编译器.它的路径应类似于:

Missing Windows SDK. Verify your SDK installation e.g. check that you have any Resource Compiler installed. It should be in a path similar to:

C:\Program Files (x86)\Microsoft SDKs\Windows\v[some version]\bin\RC.Exe

Visual Studio 2017安装

请注意,即使您选择一个C ++预定义程序包(例如我使用过Desktop development with C++,然后在Individual Components标签).

Please note the Visual Studio may not install all necessary C++ packages even when you select one of the C++ pre-defined packages (as I have e.g. used Desktop development with C++ and then added more packages under the Individual Components tab).

这是最适合我的选择(VS2017社区版,Windows 10):

Here is which selection worked for me (VS2017 Community Edition, Windows 10):

如果您有使用MFC/ATL库的项目,则需要将其添加到SDKs, libraries, and frameworks子类别下:

If you have projects using MFC/ATL libraries you need to add it under SDKs, libraries, and frameworks subcategory:

参考

  • CMake Error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
  • The CXX compiler identification is unknown
  • VS 2010 and CMake: 'rc' is not recognized as an internal or external command

这篇关于使用CMake为VS 2017生成解决方案时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆