43

I am trying to build FIAT using CMake GUI on windows 10.

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

    MSBuild.exe

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

I configured CMake to use Visual Studio 15 2017 compiler.

How can I fix this?

If needed, here is the CMakeLists.txt file

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)

As per your recommendation, I tried building from the Developer Command Prompt for VS2015 but still got the following error:

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

Here is my project's .vcxproj file

<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>  
A_Matar
  • 2,210
  • 3
  • 31
  • 53
  • edited. How can I run it manually? – A_Matar Jun 10 '17 at 22:16
  • Just type it in the command line. Such way you may check whether executable is actually exist and can be found in PATH. – Tsyvarev Jun 10 '17 at 22:39
  • 4
    You may need to start your CMake from a Developer Command Prompt for VS2017. See the entry in the Visual Studio 2017 section of the Start Menu. – vre Jun 11 '17 at 10:12
  • 2
    When I ran CMake 3.8.2 on the FIAT project you provided in the link a solution was created and I could run the build. So please restart in a new copy of your FIAT project, Then start Visual Studio 15 2017 developer command prompt and run the follwoing commands `cd FastImageAnnotationTool-master`, `mkdir build`, `cd build`, `cmake -G "Visual Studio 15 2017" ..`, `cmake --build .` in that order. – vre Jun 12 '17 at 06:28
  • Not building FIAT but in my project, I used the Visual Studio 15 2017 developer command prompt and then do `cmake -G "Visual Studio 15 2017" ..` the same error "Failed to run MSBuild command: MSBuild.exe to get the value of VCTargetsPath:" appears – pterodragon Jul 08 '17 at 14:03
  • I started experiencing this problem today, after having never experienced it before. The only thing different is that I recently installed VS 2019. – legalize Apr 05 '19 at 16:49

14 Answers14

10

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

Abhishek Jain
  • 630
  • 6
  • 26
9

For visual studio 2019,

System properties > environment variables > path, Add this one: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin

gopi jayaraman
  • 199
  • 1
  • 6
  • This is absolutely the wrong solution. You specify the VS version, and then it's CMake's job to locate the right path. – Andreas Haferburg Aug 26 '22 at 08:26
  • It worked for me. Except that I had to use c:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\ as I'm using the 2022 Enterprise version. Wonder why installation not sets that path automatically. – foobar Jun 14 '23 at 08:27
8

What Worked for me was

  1. File > Delete Cache
  2. Click Configure
  3. Selecting The right version of Visual Studio from the drop-down list, I.e. - the one that is installed on your machine. in my case, it was 'Visual Studio 15 2017' on windows 10.
Alexander Pacha
  • 9,187
  • 3
  • 68
  • 108
Yatin Khurana
  • 89
  • 1
  • 5
  • What is the value for VCTargetsPath in the generated .vcxproj file ? – Ted Jun 13 '19 at 14:00
  • Didn't work for me. Still getting the same issue. I tied Visual Studio 15 2017, Visual Studio 15 2017 ARM and Visual Studio 15 2017 Win64, getting the error no matter what I choose – KulaGGin Feb 07 '20 at 12:19
5

I had the same issue for what might be the same reason.

I configured CMake to use Visual Studio 15 2017 compiler.

[...]

I tried building from the Developer Command Prompt for VS2015

If I'm reading this correctly, you have Visual Studio 14 (i.e. Visual Studio 2015) installed and tried to configure CMake with the Visual Studio 15 (i.e. Visual Studio 2017) generator -- exactly the thing I did, unintentionally.

Pay close attention to the version names. They can be confusing. Visual Studio 15 is not the same as Visual Studio 2015. The program name may contain a four-digit year or a two-digit version number -- or both, as is the case with the CMake GUI. See https://en.wikipedia.org/wiki/Microsoft_Visual_Studio#History and compare the listed product names and version numbers.

Maria V.
  • 59
  • 1
  • 2
5

As DeJaVo said, add the directory containing MSBuild.exe to the PATH in your system environment variables, then restart CMAke. Mine was in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin

oraz
  • 277
  • 1
  • 6
  • 14
3

Are you using the Visual Studio developer's console? I find that if I cmake --build . from Window's build-in command line (cmd.exe), then my builds fail in similar ways. If I use the Visual Studio Developer's console instead, then things work better, though I need to add /p:Platform="Win32" as a tag if I call msbuild directly.. Specifically this is for tools which aren't found or incorrect paths. Using the Visual Studio command-line gives you a bunch of enviornment variables which are needed by MSBuild to compile your project.

Stewart
  • 4,356
  • 2
  • 27
  • 59
  • I tried it but still got an error, pls check the edited question above – A_Matar Jun 12 '17 at 03:18
  • Took a look at your update. It looks like Visual Studio is having problems parsing the VCPROJ file. – Stewart Jun 13 '17 at 05:07
  • 1
    Ok, one more tip. When you use cmake to generate the visual studio files, there should be a `.sln` file. Use MSBuild on the `.sln` file instead of the `.vcxproj`. – Stewart Jun 13 '17 at 06:10
3

Just encountered a variant of this problem with CMake 3.18 and Visual Studio 2019: with this generator ('Visual Studio 16 2019') the platform is now specified via the -A argument to cmake. If you specify an incorrect value for the platform as I did, you encounter this error.

The valid values are listed in the CMake documentation, for example Win64 should be specified as x64.

James Turner
  • 2,425
  • 2
  • 19
  • 24
  • Thank you, same cause for me, used `Win64` instead of `x64`. A better error message or command line validation would have been nice. For me it was cmake version 3.14.3 with msvc 2022. – user1556435 Apr 19 '23 at 13:45
1

I've hit this several times now. When you set environment variables like TEMP and TMP to a path that is not writable or doesn't exist, CMake will produce this error as it failed to run MSBUILD.exe while generating some files.

ZHANG Zikai
  • 560
  • 6
  • 15
0

I fixed by correcting Visual Studio version:

cmake -G "Visual Studio 12 2013 Win64"

Available generators :

  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".   
Dmytro
  • 1,290
  • 17
  • 21
0

install http://www.microsoft.com/en-us/download/confirmation.aspx?id=40760 MSbuild tools

Run CMD as normal user Type command MsBuild and veryfi the installation ** **Finished

Hansa Tharuka
  • 137
  • 1
  • 5
0

I'm working in node and have a C++ library as a dependency that must be built regularly. In my case installing extra build tools, etc, did not help. I had to simply uninstall all Visual Studio tools (via the installer) and then only install Visual Studio Professional.

cham
  • 8,666
  • 9
  • 48
  • 69
0

I had this issue. Fixed instantly the moment I uninstalled Visual Studio 2019. Found it in this link that makes reference to this other link

Sxubach
  • 364
  • 1
  • 2
  • 13
0

There is a bug in CMake 3.13.2 and earlier (I think): If you ask for VS 2017, and both VS 2019 and VS 2017 are installed, CMake accidentally chooses 2019, then gets confused because the paths don't work out, and prints this error.

Fixed in 3.13.3 (I think).

Andreas Haferburg
  • 5,189
  • 3
  • 37
  • 63
0

I recommend using MinGW MAkeFiles Generator. I successfully installed a stm32 library in my desired path without any error by it.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 21 '22 at 02:54