CMake:无法运行MSBuild命令:MSBuild.exe

时间:2017-06-10 22:03:23

标签: c++ msbuild cmake cmake-gui

我正在尝试使用Windows 10上的CMake GUI构建FIAT

CMake Error at CMakeLists.txt:3 (project):
  Failed to run MSBuild command:

    MSBuild.exe

  to get the value of VCTargetsPath:
Configuring incomplete, errors occurred!

我将CMake配置为使用Visual Studio 15 2017编译器。

我该如何解决这个问题?

如果需要,这里是CMakeLists.txt文件

cmake_minimum_required(VERSION 3.2)
include(CheckCXXCompilerFlag)
project(FIAT CXX)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

if(CHECK_CXX_COMPILER_USED1)
# Using Visual Studio C++
elseif("${CMAKE_CXX_COMPILER_ID}x" STREQUAL "MSVCx")
# Using Intel C++
elseif("${CMAKE_CXX_COMPILER_ID}x" STREQUAL "Intelx")
else(CHECK_CXX_COMPILER_USED1)
    # GCC or Clang
    # At least C++11
    CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
    CHECK_CXX_COMPILER_FLAG("-std=c++1z" COMPILER_SUPPORTS_CXX1Z)
    CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
    CHECK_CXX_COMPILER_FLAG("-std=c++1y" COMPILER_SUPPORTS_CXX1Y)
    CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
    if(COMPILER_SUPPORTS_CXX17)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
    elseif(COMPILER_SUPPORTS_CXX1Z)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
    elseif(COMPILER_SUPPORTS_CXX14)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
    elseif(COMPILER_SUPPORTS_CXX1Y)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
    elseif(COMPILER_SUPPORTS_CXX11)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    else(COMPILER_SUPPORTS_CXX17)
        message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
    endif(COMPILER_SUPPORTS_CXX17)

    if(CHECK_CXX_COMPILER_USED2)
    elseif("${CMAKE_CXX_COMPILER_ID}x" MATCHES "Clangx")
        # Using Clang
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-global-constructors")
    elseif("${CMAKE_CXX_COMPILER_ID}x" STREQUAL "GNUx")
        # Using GCC
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
    endif(CHECK_CXX_COMPILER_USED2)
endif(CHECK_CXX_COMPILER_USED1)

#OpenCV
FIND_PACKAGE(OpenCV REQUIRED core imgproc highgui imgcodecs)
if(OpenCV_Found)
    INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIR})
endif(OpenCV_Found)

#Boost
FIND_PACKAGE(Boost REQUIRED program_options filesystem)
if(Boost_FOUND)
    INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
else(Boost_FOUND)
    set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/local/boost_1_60_0/")
    set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/local/boost_1_60_0/lib64-msvc-14.0")
    Find_PACKAGE(Boost)
    if(Boost_FOUND)
        INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
    endif(Boost_FOUND)
endif(Boost_FOUND)

set(Boost_USE_STATIC_LIBS        OFF)
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME     OFF)
set(BOOST_ALL_DYN_LINK           OFF)

# Annotation Lib
file(GLOB_RECURSE FIAT_LIB_HEADERS
    "${FIAT_SOURCE_DIR}/src/image/*.h" "${FIAT_SOURCE_DIR}/src/annotation/*.h" "${FIAT_SOURCE_DIR}/src/tools/*.h"
)

file(GLOB_RECURSE FIAT_LIB_SRC
    "${FIAT_SOURCE_DIR}/src/image/Image.cpp" "${FIAT_SOURCE_DIR}/src/annotation/*.cpp" "${FIAT_SOURCE_DIR}/src/tools/*.cpp"
)

add_library(utilities ${INCLUDE_DIRECTORIES} ${FIAT_LIB_HEADERS} ${FIAT_LIB_SRC})
target_link_libraries (utilities ${Boost_LIBRARIES} ${OpenCV_LIBRARIES} )

if(CHECK_CXX_COMPILER_USED_UTILITIES)

elseif("${CMAKE_CXX_COMPILER_ID}x" STREQUAL "MSVCx")
  # using Visual Studio C++
elseif("${CMAKE_CXX_COMPILER_ID}x" STREQUAL "Intelx")
  # using Intel C++
else()
  # GCC or Clang
    target_link_libraries (utilities m )
endif(CHECK_CXX_COMPILER_USED_UTILITIES)

# Annotate
file(GLOB_RECURSE FIAT_ANNOTATE_HEADERS
)

file(GLOB_RECURSE FIAT_ANNOTATE_SRC
    "${FIAT_SOURCE_DIR}/src/app/annotate.cpp"
)

add_executable(annotate ${INCLUDE_DIRECTORIES} ${FIAT_LIB_HEADERS} ${FIAT_ANNOTATE_HEADERS} ${FIAT_ANNOTATE_SRC})
target_link_libraries(annotate utilities ${Boost_LIBRARIES} ${OpenCV_LIBRARIES})


if(CHECK_CXX_COMPILER_USED_ANNOTATE)
elseif("${CMAKE_CXX_COMPILER_ID}x" STREQUAL "MSVCx")
  # using Visual Studio C++
elseif("${CMAKE_CXX_COMPILER_ID}x" STREQUAL "Intelx")
  # using Intel C++
else()
  # GCC or Clang
    target_link_libraries (annotate m)
endif(CHECK_CXX_COMPILER_USED_ANNOTATE)

根据您的建议,我尝试从Developer Command Prompt for VS2015构建,但仍然出现以下错误:

msbuild FIAT.vcxproj /p:configuration=debug
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 6/12/2017 5:16:26 AM.
Project "E:\Work\FastImageAnnotationTool-master\FIAT.vcxproj" on node 1 (default targets).
E:\Work\FastImageAnnotationTool-master\FIAT.vcxproj(1,1): error MSB4067: The element <#text> beneat
h element <Project> is unrecognized.
Done Building Project "E:\Work\FastImageAnnotationTool-master\FIAT.vcxproj" (default targets) -- FA
ILED.


Build FAILED.

"E:\Work\FastImageAnnotationTool-master\FIAT.vcxproj" (default target) (1) ->
  E:\Work\FastImageAnnotationTool-master\FIAT.vcxproj(1,1): error MSB4067: The element <#text> bene
ath element <Project> is unrecognized.

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.03

这是我的项目.vcxproj文件

<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
  <ItemGroup>  
    <ProjectConfiguration Include="Debug|Win32">  
      <Configuration>Debug</Configuration>  
      <Platform>Win32</Platform>  
    </ProjectConfiguration>  
    <ProjectConfiguration Include="Release|Win32">  
      <Configuration>Release</Configuration>  
      <Platform>Win32</Platform>  
    </ProjectConfiguration>  
  </ItemGroup>  
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.default.props" />  
  <PropertyGroup>  
    <ConfigurationType>Application</ConfigurationType>  
    <PlatformToolset>v120</PlatformToolset>  
  </PropertyGroup>  
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />  
  Annotation.cpp Annotations.cpp app/annotate.cpp - image/Image.cpp test/image-test.cpp - tools/tools.cpp

  <ItemGroup>  
    <ClInclude Include="/src/annotation/Annotation.cpp" />  
  </ItemGroup>  
  <ItemGroup>  
    <ClInclude Include="/src/annotation/Annotation.h" />  
  </ItemGroup>  

  <ItemGroup>  
    <ClInclude Include="/src/annotation/Annotations.cpp" />  
  </ItemGroup>  
  <ItemGroup>  
    <ClInclude Include="/src/annotation/Annotation.h" />  
  </ItemGroup>  

  <ItemGroup>  
    <ClInclude Include="/src/app/annotate.cpp" />  
  </ItemGroup>  

  <ItemGroup>  
    <ClInclude Include="/src/image/Image.cpp" />  
  </ItemGroup>  
  <ItemGroup>  
    <ClInclude Include="/src/image/Image.h" />  
  </ItemGroup>

  <ItemGroup>  
    <ClInclude Include="/src/test/image-test.cpp" />  
  </ItemGroup> 

  <ItemGroup>  
    <ClInclude Include="/src/tools/tools.cpp" />  
  </ItemGroup>  
  <ItemGroup>  
    <ClInclude Include="/src/tools/tools.h" />  
  </ItemGroup> 

  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Targets" />  
</Project>  

12 个答案:

答案 0 :(得分:6)

The error reads a missing Path to MSBuild.exe

The possible solution to this is to install MSBuild.exe

Scroll down to Other Tools and Frameworks, and install Build Tools For Visual Studio

答案 1 :(得分:6)

为我工作的是

  1. 文件&gt;删除缓存
  2. 单击“配置”
  3. 从下拉列表中选择正确版本的Visual Studio,即。 - 您机器上安装的那个。在我的情况下,它是&#39; Visual Studio 15 2017&#39;在Windows 10上。

答案 2 :(得分:4)

出于同样的原因,我遇到了同样的问题。

  

我将CMake配置为使用Visual Studio 15 2017编译器。

     

[...]

     

我尝试从Developer Command Prompt for VS2015

构建

如果我正确阅读此内容,您已安装Visual Studio 14(即Visual Studio 2015),并尝试使用CMake配置Visual Studio 15(即Visual Studio 2017生成器 - 完全是我无意中做的事情。

密切注意版本名称。他们可能会令人困惑。 Visual Studio 15Visual Studio 2015不同。程序名称可能包含四位数年份或两位数版本号 - 或两者兼有,如CMake GUI的情况。请参阅https://en.wikipedia.org/wiki/Microsoft_Visual_Studio#History并比较列出的产品名称和版本号。

答案 3 :(得分:4)

对于Visual Studio 2019,

系统属性>环境变量>路径, 添加以下内容:C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Community \ MSBuild \ Current \ Bin

答案 4 :(得分:3)

您使用的是Visual Studio开发人员的控制台吗?我发现如果我从Window的内置命令行(cmd.exe)cmake --build .,那么我的构建会以类似的方式失败。如果我使用Visual Studio Developer的控制台,那么事情会更好,但如果我直接调用/p:Platform="Win32"我需要添加msbuild作为标记。具体来说,这是针对未找到的工具或错误的路径。使用Visual Studio命令行为您提供了一堆MSBuild编译项目所需的环境变量。

答案 5 :(得分:3)

如DeJaVo所说,将包含MSBuild.exe的目录添加到系统环境变量中的PATH中,然后重新启动CMAke。我在C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin

答案 6 :(得分:1)

我现在已经好几次了。当您将TMPpublic function login(Request $request) { if(Auth::check(['email' => $request->email, 'password' => $request->password])){ $user = Auth::user();///print_r($user);exit; $token = $user->createToken('MyApp')->accessToken; return $this->sendLoginResponse($request, $user, $token); } //$this->incrementLoginAttempts($request); return $this->sendFailedLoginResponse($request); } protected function sendLoginResponse(Request $request, $user, $token){ //$this->clearLoginAttempts($request); return $this->authenticated($request, $user, $token); } protected function authenticated(Request $request, $user, $token) { setcookie("oauth_token", $token); return redirect('/'); return response()->json([ 'token' => $token, ]); } protected function sendFailedLoginResponse(Request $request){ return response()->json([ 'message' => "not found", ], 401); } 等环境变量设置为不可写或不存在的路径时,CMake将生成此错误,因为它在生成某些文件时无法运行MSBUILD.exe。

答案 7 :(得分:0)

我通过更正Visual Studio版本进行了修复:

cmake -G "Visual Studio 12 2013 Win64"

可用的发电机:

  Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files. 
                                 Optional [arch] can be "Win64" or "ARM".    
  Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files. 
                                 Optional [arch] can be "Win64" or "ARM".    
  Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files. 
                                 Optional [arch] can be "Win64" or "ARM".    
  Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files. 
                                 Optional [arch] can be "Win64" or "ARM".    
  Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files. 
                                 Optional [arch] can be "Win64" or "IA64".   
  Visual Studio 9 2008 [arch]  = Generates Visual Studio 2008 project files. 
                                 Optional [arch] can be "Win64" or "IA64".   

答案 8 :(得分:0)

安装 http://www.microsoft.com/en-us/download/confirmation.aspx?id=40760 MSbuild工具

以普通用户身份运行CMD 键入命令MsBuild并非常安装** **完成

答案 9 :(得分:0)

我正在节点上工作,并且有一个C ++库作为必须定期构建的依赖项。就我而言,安装额外的构建工具等并没有帮助。我只需要简单地卸载所有Visual Studio工具(通过安装程序),然后仅安装Visual Studio Professional。

答案 10 :(得分:0)

在CMake 3.18和Visual Studio 2019中遇到了此问题的一个变体:使用此生成器(Visual Studio 16 2019),现在可以通过-A的{​​{1}}参数指定平台。如果像我一样为平台指定了不正确的值,则会遇到此错误。

CMake文档中列出了有效值,例如,cmake应指定为Win64

答案 11 :(得分:0)

我遇到了这个问题。在我卸载 Visual Studio 2019 的那一刻立即修复。在引用 this link

this other link 中找到它