windows - CMake 和 Visual Studio:无法运行 MSBuild.exe
问题描述
我正在尝试构建 OpenCV 的源文件并使用 CMake 生成一个 Visual Studio 项目。我面临的问题似乎无法通过这些给出的以下建议解决:此处- 使用 CMake 构建时选择 Visual Studio 的正确版本(例如 v16 2019),安装MSBuild.exe
并将其位置添加到系统 PATH -,此处- 安装 Windows SDK -在这里- 在 Visual Studio 中安装有关 CMake/C++ 所需的工作负载并重新启动它。
然后我请求你的帮助。我目前正在与:
- 操作系统:Windows 8.1 Pro 64 位
- CMake (GUI) 版本 3.17.2,位于
C:\Program Files\CMake\bin
- Microsoft Visual Studio 2019 版本 16.6.0
- 微软构建。exe 版本 16.6.0,位于
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin
- OpenCV 4.3.0,位于
D:\opencv
; sdksetup.exe
版本 8.100,位于C:\Program Files (x86)\Microsoft SDKs\Windows Kits\8.1\StandaloneSDK
- 我的系统环境变量中的路径是:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\MinGW\bin;C:\Program Files\CMake\bin\;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\;C:\Program Files (x86)\Microsoft SDKs\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\
我以管理员权限打开 CMake,然后选择“Visual Studio 16 2019”作为生成器,单击“配置”按钮时总是弹出以下错误:
配置过程出错,项目文件可能无效。
我试着用两种不同的方法来做CMakeLists.txt
,一个简单的,一个完整的。
简单的脚本
# cmake needs this line
cmake_minimum_required(VERSION 3.1)
# Define project name
project(opencv_example_project)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# Declare the executable target built from your sources
add_executable(opencv_example example.cpp)
# Link your application with OpenCV libraries
target_link_libraries(opencv_example PRIVATE ${OpenCV_LIBS})
在这种情况下,状态栏警告:
CMake Error at CMakeLists.txt:5 (project):
Failed to run MSBuild command:
C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe
to get the value of VCTargetsPath:
Microsoft(R) Build Engine versÆo 16.6.0+5ff7b0c9e para .NET Framework
Copyright (C) Microsoft Corporation. Todos os direitos reservados.
完整的脚本
可以在这里找到https://github.com/opencv/opencv/blob/master/CMakeLists.txt。我小心地删除了所有 CMakeCache 文件并删除了 CMake-GUI 中的缓存。在这种情况下,状态栏警告:
CMake Error at CMakeLists.txt:106 (enable_language):
Failed to run MSBuild command:
C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe
to get the value of VCTargetsPath:
Microsoft(R) Build Engine versÆo 16.6.0+5ff7b0c9e para .NET Framework
刚刚结束:在 Microsoft Visual Studio 的“关于”部分,我们可以看到加载了哪些工作负载:
- 微软 Visual Studio 社区 2019
- 版本 16.6.0
- VisualStudio.16.Release / 16.6.0 + 30114.105
- 微软 .NET 框架
- 版本 4.8.03761
- 安装版本:社区
- Visual C++ 2019 00435-60000-00000-AA905
- 微软 Visual C++ 2019
- Google Test 1.0 的测试适配器
- 启用 Visual Studio 测试工具,并为 Google Test 记录单元测试。使用条款和第三方通知可在扩展的安装目录中找到。
- ASP.NET 和 Web 工具 2019 16.6.936.3669
- ASP.NET 和 Web 工具 2019
- Microsoft Visual C++ 1.0 向导
- Microsoft Visual C++ 向导
- IntelliCode 1.0 扩展
- Visual Studio 的详细 IntelliCode 扩展信息
- 工具 C# 3.6.0-4.20251.5 + 910223b64f108fcf039012e0849befb46ace6e66
- IDE 中使用的 C# 组件。根据您的项目类型和设置,可能会使用不同版本的编译器。
- Visual Basic 工具 3.6.0-4.20251.5 + 910223b64f108fcf039012e0849befb46ace6e66
- IDE 中使用的 Visual Basic 组件。根据您的项目类型和设置,可能会使用不同版本的编译器。
- CMake 1.0 的 Visual Studio 工具(有趣)
- 用于 CMake 的 Visual Studio 工具(嗯,好吧)
- NuGet 包管理器 5.6.0
- Visual Studio 中的 NuGet 包管理器。有关 NuGet 的更多信息,请访问https://docs.nuget.org/
- 微软 JVM 调试器 1.0
- 支持将 Visual Studio 调试器连接到与 JDWP 兼容的 Java 虚拟机
- 基于微软 MI 的调试器 1.0
- 支持将 Visual Studio 连接到兼容 MI 的调试器
- Visual Studio Code 1.0 调试适配器主机包
- 在 Visual Studio 中托管 Visual Studio Code 调试适配器的互操作层
- Microsoft Visual Studio 1.0 VC 包
- Microsoft Visual Studio VC 包
- 项目服务包扩展 1.0
- ProjectServicesPackage Visual Studio 扩展详细信息
- Boost.Test 1.0 的测试适配器
- 通过为 Boost.Test 编写的单元测试启用 Visual Studio 的测试工具。使用条款和第三方声明可在扩展安装目录中找到。
- 用于多平台移动开发的 Visual C++ (Android) 16.0.30014.67
- 用于多平台移动开发 (Android) 的 Visual C++
非常感谢!
解决方案
推荐阅读
- python - 在 Django 中,为什么错误“TypeError at / string indices must be integers”?
- azure-cosmosdb - 在其他条件相同的情况下,更精细的分区键是否会影响 RU 成本?
- numpy - 在曲线拟合函数中实现线性方程
- c# - 使用 C# 代码从 MS Exchange 邮箱中读取电子邮件
- r - R中“选择”的问题
- java - Java 反射 - 识别方法返回类型
- php - PHP 将值与 HTML 特殊字符进行比较
- javascript - 如何在 html 中的图像映射中填充颜色?
- expo - 在 UIManager 中找不到 Expo SDK43“AndroidCheckBox”
- neo4j - Neo4j - 如何在多个对立关系上找到节点?