[英]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.