I'm trying to build the OpenCV's source files and generate a Visual Studio project using CMake. I'm facing a problem that seems not solved neither with these given following recommendations: here - select the Visual Studio's correct version (e.g. v16 2019) when building with CMake, install MSBuild.exe
and add its location to the system PATH -, here - install Windows SDK - and here - install required workload in Visual Studio regarding CMake/C++ and reboot it.
Then I ask for your kind help. I'm currently working with:
- OS: Windows 8.1 Pro 64 bits
- CMake (GUI) Version 3.17.2, located at
C:\Program Files\CMake\bin
- Microsoft Visual Studio 2019 version 16.6.0
- MSBuild. exe version 16.6.0, located at
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin
- OpenCV 4.3.0, located at
D:\opencv
; sdksetup.exe
version 8.100, located atC:\Program Files (x86)\Microsoft SDKs\Windows Kits\8.1\StandaloneSDK
- My Path in my system's environment variables is:
%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\
I open the CMake with admin rights, then select "Visual Studio 16 2019" as generator, and I always got the following error pop-up when clicking in the "Configure" button:
Error in configuration process, projects files may be invalid.
I tried to do it with two different CMakeLists.txt
, a simple one and a complete one.
The simple script
# 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})
In this case, the status bar warned:
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.
The complete script
Which can be found here https://github.com/opencv/opencv/blob/master/CMakeLists.txt. I took care to delete all CMakeCache files and to delete cache inside CMake-GUI. In this case, the status bar warned:
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
Just to finish: in "About" section inside Microsoft Visual Studio, we can see which Workloads were loaded:
- Microsoft Visual Studio Community 2019
- Version 16.6.0
- VisualStudio.16.Release / 16.6.0 + 30114.105
- Microsoft .NET Framework
- Version 4.8.03761
- Installed Version: Community
- Visual C ++ 2019 00435-60000-00000-AA905
- Microsoft Visual C ++ 2019
- Test Adapter for Google Test 1.0
- Enables Visual Studio testing tools with recorded unit tests for Google Test. The terms of use and Third Party Notices are available in the extension's installation directory.
- ASP.NET and Web Tools 2019 16.6.936.3669
- ASP.NET and Web Tools 2019
- Microsoft Visual C ++ 1.0 wizards
- Microsoft Visual C ++ wizards
- IntelliCode 1.0 extension
- Detailed IntelliCode Extension Information for Visual Studio
- Tools C # 3.6.0-4.20251.5 + 910223b64f108fcf039012e0849befb46ace6e66
- C # components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
- Visual Basic Tools 3.6.0-4.20251.5 + 910223b64f108fcf039012e0849befb46ace6e66
- Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
- Visual Studio tools for CMake 1.0 (interesting)
- Visual Studio tools for CMake (uhmm okay)
- NuGet Package Manager 5.6.0
- NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
- Microsoft JVM Debugger 1.0
- Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
- Microsoft MI-Based Debugger 1.0
- Provides support for connecting Visual Studio to MI compatible debuggers
- Visual Studio Code 1.0 Debug Adapter Host Package
- Interoperability layer to host Visual Studio Code debug adapters in Visual Studio
- Microsoft Visual Studio 1.0 VC package
- Microsoft Visual Studio VC package
- ProjectServicesPackage Extension 1.0
- ProjectServicesPackage Visual Studio Extension Detailed Info
- Test Adapter for Boost.Test 1.0
- Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.
- Visual C ++ for Multiplatform Mobile Development (Android) 16.0.30014.67
- Visual C ++ for Multiplatform Mobile Development (Android)
Thanks a lot!