'How to fix warning "Found OpenCV Windows Pack but it has no binaries compatible with your configuration"?

I am trying to use OpenCV in VS Code. Here's what I've done:

Installed OpenCV for windows.

Added "C:\opencv\build\x64\vc15\bin","C:\opencv\build\x64\vc15\lib" PATH environment variable.

Here's my CMakeLists.txt file.

cmake_minimum_required(VERSION 3.0.0)
project(opencvtest VERSION 0.1.0)

include(CTest)
enable_testing()

find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )

add_executable(opencvtest main.cpp)

target_link_libraries( opencvtest ${OpenCV_LIBS} )

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

But the file throws the following error:

[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=C:\TDM-GCC-64\bin\x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\TDM-GCC-64\bin\x86_64-w64-mingw32-g++.exe -Hc:/Users/Administrator/Desktop/open -Bc:/Users/Administrator/Desktop/open/build -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- OpenCV ARCH: x64
[cmake] -- OpenCV RUNTIME: mingw
[cmake] -- OpenCV STATIC: OFF
[cmake] CMake Warning at C:/opencv/build/OpenCVConfig.cmake:190 (message):
[cmake]   Found OpenCV Windows Pack but it has no binaries compatible with your
[cmake]   configuration.
[cmake] 
[cmake]   You should manually point CMake variable OpenCV_DIR to your build of OpenCV
[cmake]   library.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:7 (find_package)
[cmake] 
[cmake] 
[cmake] CMake Error at CMakeLists.txt:7 (find_package):
[cmake]   Found package configuration file:
[cmake] 
[cmake]     C:/opencv/build/OpenCVConfig.cmake
[cmake] 
[cmake]   but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be
[cmake]   NOT FOUND.
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!

I am trying to run a C++ file in VS Code that includes <opencv2/opencv.hpp>.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source