简体   繁体   English

为什么 cl.exe(Visual Studio 编译器)无法使用 CMake(错误报告)编译项目?

[英]How come cl.exe (Visual Studio compiler) fails to compile a project with CMake (error-report)?

Since I'm new to CMake, I've been attempting to set up a basic CMake application using CMake GUI while following this tutorial .由于我是 CMake 的新手,我一直在尝试使用 CMake GUI 设置基本的 CMake 应用程序,同时遵循本教程 Everything worked fine up until the point when I clicked "Configure".在我单击“配置”之前一切正常。 I changed Visual Studio 14 2015 to Visual Studio 16 2019 (because I have a more recent version of Visual Studio) and "Hello World" to "Basic", and after clicking "Configure", I received an error telling me the Visual Studio compiler, cl.exe, could not successfully compile a test program.我将 Visual Studio 14 2015 更改为 Visual Studio 16 2019(因为我有更新版本的 Visual Studio)和“Hello World”更改为“Basic”,单击“配置”后,我收到一条错误消息,告诉我 Visual Studio 编译器, cl.exe, 无法成功编译测试程序。 More details below.更多详情如下。

I have already created a CMake project using Visual Studio's built in work-space and it has successfully compiled my project;我已经使用 Visual Studio 的内置工作空间创建了一个 CMake 项目,它已经成功编译了我的项目; however, this is undesirable to me as Visual Studio adds a bunch of files to my project that make it look more complicated for a beginner and dirty up my project.但是,这对我来说是不可取的,因为 Visual Studio 向我的项目中添加了一堆文件,这使得它对于初学者来说看起来更复杂并且弄脏了我的项目。 This tells me that my Visual Studio installation is not defective, and that something is wrong with CMake.这告诉我我的 Visual Studio 安装没有缺陷,并且 CMake 有问题。

For those that want to know, my CMakeLists.txt looks like this:对于那些想知道的人,我的 CMakeLists.txt 如下所示:

cmake_minimum_required(VERSION "3.10")

project("Basic")

add_executable("${PROJECT_NAME}" "main.cpp")

install(TARGETS "${PROJECT_NAME}" DESTINATION bin)
install(FILES "main.cpp" DESTINATION src)

I expect CMake to configure my project correctly like it does for the guy in the tutorial video, but instead I get an error while configuring that says this (Username replaced by "potato" for personal reasons):我希望 CMake 能够像教程视频中的那个人一样正确配置我的项目,但是在配置时出现错误(出于个人原因,用户名替换为“potato”):

Selecting Windows SDK version 10.0.18362.0 to target Windows 6.1.7601.
The C compiler identification is MSVC 19.23.28106.4
The CXX compiler identification is MSVC 19.23.28106.4
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/potato/Desktop/Basic/build/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe cmTC_09d22.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=16.0 /v:m && Microsoft (R) Build Engine version 16.3.1+1def00d3d for .NET Framework

    Copyright (C) Microsoft Corporation. All rights reserved.



    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(5589,7): error MSB4023: Cannot evaluate the item metadata "%(FullPath)". The item metadata "%(FullPath)" cannot be applied to the path "@(_DebugSymbolsIntermediatePath->'C:\Users\potato\Desktop\Basic\build\CMakeFiles\CMakeTmp\Debug\%(Filename)%(Extension)')". Illegal characters in path. [C:\Users\potato\Desktop\Basic\build\CMakeFiles\CMakeTmp\cmTC_09d22.vcxproj]






  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)


Configuring incomplete, errors occurred!
See also "C:/Users/potato/Desktop/Basic/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/potato/Desktop/Basic/build/CMakeFiles/CMakeError.log".

CMakeError.log states this: CMakeError.log 指出:

Determining if the C compiler works failed with the following output:
Change Dir: C:/Users/potato/Desktop/Basic/build/CMakeFiles/CMakeTmp

Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe cmTC_09d22.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=16.0 /v:m && Microsoft (R) Build Engine version 16.3.1+1def00d3d for .NET Framework

Copyright (C) Microsoft Corporation. All rights reserved.



C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(5589,7): error MSB4023: Cannot evaluate the item metadata "%(FullPath)". The item metadata "%(FullPath)" cannot be applied to the path "@(_DebugSymbolsIntermediatePath->'C:\Users\potato\Desktop\Basic\build\CMakeFiles\CMakeTmp\Debug\%(Filename)%(Extension)')". Illegal characters in path. [C:\Users\potato\Desktop\Basic\build\CMakeFiles\CMakeTmp\cmTC_09d22.vcxproj]

Perhaps I should also note that the real username, replaced by "potato", contains an apostrophe.也许我还应该注意,由“potato”代替的真实用户名包含一个撇号。 This may be only minimal, but it could be important as I read the error "Illegal characters in path."这可能只是最小的,但它可能很重要,因为我阅读了错误“路径中的非法字符”。

It turns out that the problem in my case is that the username for my computer contains an apostrophe.事实证明,我的问题是我的计算机的用户名包含撇号。 Definitely a strange bug.绝对是一个奇怪的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CMake 和 Visual Studio 2015 - C 编译器 cl.exe 无法编译简单的测试程序 - CMake and Visual studio 2015 - The C compiler cl.exe is not able to compile a simple test program 针对此cpp代码使用cl.exe(Visual Studio 2008)编译错误 - Compile error using cl.exe (Visual Studio 2008) for this cpp code 在Visual Studio C ++中编译时出现错误2,代码退出MSB6006“ CL.exe” - Error MSB6006 “CL.exe” exited with code 2 in compile in visual studio c++ 编译Visual Studio C ++项目时出错-cl.exe错误 - Error compiling Visual Studio C++ project - error with cl.exe 如何使用从 cl.exe(Visual Studio C/C++ 编译器)生成的 a.exe 从命令行调试 a.exe? - How can I debug a .exe from the command line with a .exe generated from cl.exe (Visual Studio C/C++ Compiler)? Visual Studio 2008中的cl.exe包装器 - cl.exe wrapper in Visual Studio 2008 Visual Studio找不到cl.exe - Visual Studio not finding cl.exe c ++编译问题—使用cl.exe可以正常编译,但无法从Visual Studio 2015进行编译 - c++ compiling issue — Compiles fine with cl.exe but will not compile from Visual Studio 2015 从2012年到2017年将Visual Studio项目迁移到错误CL.exe - migrating visual studio project from 2012 to 2017 errors CL.exe Visual Studio 2017 - 错误MSB6006:“CL.exe”退出代码2 - Visual studio 2017 - error MSB6006: “CL.exe” exited with code 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM