【问题标题】:CMake with Microsoft Visual C++ Build Tools使用 Microsoft Visual C++ 构建工具的 CMake
【发布时间】:2017-09-10 20:36:38
【问题描述】:

编辑: 将其发布到他们的问题跟踪器并与一些 CMake 开发人员一起逐步完成后,这实际上不是 CMake 问题。我的 MSBuild 安装出现问题,导致它返回“操作成功完成”。错误。总体上仍然没有解决问题,但这缩小了潜在原因。


我正在尝试使用 MS Visual C++ Build Tools 2015 在 Windows 上构建 CMake 项目(注意:不是完整的 Visual Studio)。然而,CMake 显然无法找到 cl.exe

cmake ..
-- Building for: Visual Studio 14 2015
-- 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.

我怀疑这是因为 CMake 期望在 Visual Studio 安装中找到编译器,但也许独立构建工具将它安装在不同的位置?是否可以将 CMake 配置为在别处寻找编译器?

编辑:为了避免这种可能性,肯定安装了 cl.exe。当我打开 Visual C++ shell(将工具添加到路径)时,cl.exe 输出:

cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

这与我运行 cmake .. 的环境相同,因此 cl.exe 肯定在 CMake 发现的路径上。

编辑 2:查看 CMakeError.log 文件,我看到以下几个变体

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler:  
Build flags: 
Id flags:  

The output was:
1
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 4/14/2017 11:58:13 AM.
Project "E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj" on node 1 (default targets).
PrepareForBuild:
  Creating directory "Debug\".
  Creating directory "Debug\CompilerIdCXX.tlog\".
InitializeBuildStatus:
  Creating "Debug\CompilerIdCXX.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /nologo /W0 /WX- /Od /Oy- /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc140.pdb" /Gd /TP /analyze- /errorReport:queue CMakeCXXCompilerId.cpp
TRACKER : error TRK0002: Failed to execute command: ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe" @C:\Users\<user>\AppData\Local\Temp\tmpa0925a9f05d5426d82afdcee8d722031.rsp". The operation completed successfully. [E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj]


Done Building Project "E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj" (default targets) -- FAILED.

Build FAILED.

"E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(ClCompile target) -> 
  TRACKER : error TRK0002: Failed to execute command: ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe" @C:\Users\<user>\AppData\Local\Temp\tmpa0925a9f05d5426d82afdcee8d722031.rsp". The operation completed successfully. [E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.21

这看起来像是某种输出兼容性问题,尤其是“错误:操作成功完成”。线。我正在使用 CMake 3.8.0-rc4 和 Visual C++ 2015 构建工具。有什么想法吗?

编辑 3: 我认为从 3.8.0-rc4 升级到 3.8.0 可能会修复它,但无济于事。我还认为我正在使用 64 位 CMake 尝试构建 32 位程序,所以我也更改了它。还没有运气。

编辑 4: 此外,为了记录,这确实在安装了完整 VS 2015 的 PC 上使用 CMake 构建。

【问题讨论】:

  • 是的。而且我已经仔细检查过我可以在那个 shell 中手动调用 cl.exe 就好了。
  • 这就是我运行它以获得上述输出的地方,甚至是相同的终端实例。
  • 这看起来像一个 CMake 错误。尝试使用尽可能多的信息报告错误here。像您对问题一样添加尽可能多的信息也做得很好!
  • cmake bugtracker 中的问题在哪里?我在 windows server 2008r2 和 windows 10 上遇到了同样的问题。我在两台机器上都安装了 Microsoft Visual C++ Build Tools 2015? CMake 是否正式支持独立编译器?
  • Here's the issue. 虽然在我的情况下看起来是 MSBuild.exe 的问题,而不是 CMake。 MSBuild.exe 似乎没有构建我在 MS 网站上找到的一些示例项目。

标签: c++ visual-c++ cmake


【解决方案1】:

我不确定我是否为您的The operation completed successfully 问题提供了解决方案,但我能够使用 cmake 3.8.1 和 C++2015 BuildTools 编译一个 [大型] 实际项目。

诀窍就是使用“VS2015 x64 Native Tools Command Prompt”(或 x86)。您可以使用此提示符调用 cmake,或者您在正常提示符下call此提示符,它会正确设置您的路径。

REM Set up the include/lib paths of Visual Studio
call "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat" amd64

cd to_build_dir

REM Call cmake with the right parameters
"C:\Program Files\CMake\bin\cmake.exe" .......

REM Build the XYZ project
MSBuild.exe SOLUTION_FILE.sln /t:XYZ .......

正如我所写,我不确定它是否能解决您的错误,因为我无法重现它。但是,我知道我的项目只有在我使用正确的提示时才能编译。当我不使用它时,我会得到一些error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the &lt;Import&gt; declaration is correct, and that the file exists on disk.

【讨论】:

  • 我尝试了你的建议。但它似乎并不存在路径 "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuiltools.bat" 。我在两台不同的机器上安装了 C++2015 BuildTools。他们俩都没有那条路。它也不在“C:\Program Files\Microsoft Visual C++ Build Tools\vcbuiltools.bat”下。知道你是从哪里得到它的吗?
  • 不,我不记得我 3 年前做了什么,我现在无法安装它。您可以尝试在他们可能所在的Program Files (x86) 文件夹中搜索vc*bat
  • 我知道这是一个老话题。但这正是我现在正在处理的问题。我在任何地方都找不到那个文件。它似乎不是作为 MSBuild 2015 安装的一部分安装的。
猜你喜欢
  • 1970-01-01
  • 2018-07-10
  • 1970-01-01
  • 2013-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-30
相关资源
最近更新 更多