使用cmake生成Visual Studio项目时出现此错误。对于上下文,我尝试在Exercism做一些练习(需要注册)。我已经在VS中安装了v141(请参见下面的屏幕截图)。似乎是什么问题?
操作系统:Windows 10 CMake的:3.12.4 提升:1.55.0 Visual Studio企业版2017 15.8.4
# Get the exercise name from the current directory
get_filename_component(exercise ${CMAKE_CURRENT_SOURCE_DIR} NAME)
# Basic CMake project
cmake_minimum_required(VERSION 2.8.11)
# Name the project after the exercise
project(${exercise} CXX)
# Locate Boost libraries: unit_test_framework, date_time and regex
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.59 REQUIRED COMPONENTS unit_test_framework date_time regex)
# Enable C++11 features on gcc/clang
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
set(CMAKE_CXX_FLAGS "-std=c++11")
endif()
# Configure to run all the tests?
if(${EXERCISM_RUN_ALL_TESTS})
add_definitions(-DEXERCISM_RUN_ALL_TESTS)
endif()
# Get a source filename from the exercise name by replacing -'s with _'s
string(REPLACE "-" "_" file ${exercise})
# Implementation could be only a header
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.cpp)
set(exercise_cpp ${file}.cpp)
else()
set(exercise_cpp "")
endif()
# Build executable from sources and headers
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
# We need boost includes
target_include_directories(${exercise} PRIVATE ${Boost_INCLUDE_DIRS})
# We need boost libraries
target_link_libraries(${exercise} ${Boost_LIBRARIES})
# Tell MSVC not to warn us about unchecked iterators in debug builds
if(${MSVC})
set_target_properties(${exercise} PROPERTIES
COMPILE_DEFINITIONS_DEBUG _SCL_SECURE_NO_WARNINGS)
endif()
# Run the tests on every build
add_custom_command(TARGET ${exercise} POST_BUILD COMMAND ${exercise})
C:\Users\hurrjae\Exercism\cpp\hello-world>cmake -DBOOST_INCLUDEDIR:PATH="C:\Program Files\Boost\boost_1_55_0"
CMake Error at CMakeLists.txt:8 (project):
Failed to run MSBuild command:
C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe
to get the value of VCTargetsPath:
Microsoft (R) Build Engine version 15.8.168+ga8fba1ebd7 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 20/11/2018 9:50:14 PM.
Project "C:\Users\hurrjae\Exercism\cpp\hello-world\CMakeFiles\3.12.4\VCTargetsPath.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v141 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install v141 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\hurrjae\Exercism\cpp\hello-world\CMakeFiles\3.12.4\VCTargetsPath.vcxproj]
Done Building Project "C:\Users\hurrjae\Exercism\cpp\hello-world\CMakeFiles\3.12.4\VCTargetsPath.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\Users\hurrjae\Exercism\cpp\hello-world\CMakeFiles\3.12.4\VCTargetsPath.vcxproj" (default target) (1) ->
(PlatformPrepareForBuild target) ->
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v141 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install v141 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\hurrjae\Exercism\cpp\hello-world\CMakeFiles\3.12.4\VCTargetsPath.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.18
Exit code: 1
-- Configuring incomplete, errors occurred!
See also "C:/Users/hurrjae/Exercism/cpp/hello-world/CMakeFiles/CMakeOutput.log".
The system is: Windows - 10.0.17134 - AMD64
答案 0 :(得分:0)
您包含在报告中的错误消息包含建议您可以重新定位项目,并告诉您如何执行。我已经成功了。或者,您可以安装v141构建工具,这些错误消息说这些信息丢失了,不必重新定位。