【发布时间】:2019-10-23 04:11:06
【问题描述】:
由于我是 CMake 新手,我一直在尝试使用 CMake GUI 设置基本的 CMake 应用程序,同时关注 this tutorial。在我单击“配置”之前一切正常。我将 Visual Studio 14 2015 更改为 Visual Studio 16 2019(因为我有更新版本的 Visual Studio)和“Hello World”更改为“Basic”,单击“配置”后,我收到一条错误消息,告诉我 Visual Studio 编译器, cl.exe, 无法成功编译测试程序。更多详情如下。
我已经使用 Visual Studio 的内置工作空间创建了一个 CMake 项目,它已经成功编译了我的项目;但是,这对我来说是不可取的,因为 Visual Studio 向我的项目中添加了一堆文件,这使得它对于初学者来说看起来更复杂并且弄脏了我的项目。这告诉我我的 Visual Studio 安装没有缺陷,并且 CMake 有问题。
对于那些想知道的人,我的 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)
我希望 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 声明如下:
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]
也许我还应该注意,由“potato”代替的真实用户名包含一个撇号。这可能只是最小的,但它可能很重要,因为我阅读了错误“路径中的非法字符”。
【问题讨论】:
-
创建一个
c:\test文件夹,将项目放在那里,然后重试。如果这不起作用,您至少可以消除撇号。 -
是的,我应该想到这一点。它确实有效。我会在这里发布答案。
标签: c++ visual-studio cmake visual-studio-2019