Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error using cmake on Windows with Visual Studio 2017 and OpenCV 3.4.3

Hi,

I am following this page from OpenCV Docs to use cmake with OpenCV.

This is my file structure,

- displayopencv\
-- CMakeLists.txt
-- DisplayImage.cpp

CMakeLists.txt contains,

cmake_minimum_required(VERSION 2.8)
set(OpenCV_DIR C:/OpenCV34/opencv/build)
project( DisplayImage )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

I run cmake . in this directory inside command prompt and get the following error,

-- Selecting Windows SDK version 10.0.16299.0 to target Windows 10.0.17134.
-- OpenCV ARCH: x86
-- OpenCV RUNTIME: vc14
-- OpenCV STATIC: OFF
CMake Warning at C:/OpenCV34/opencv/build/OpenCVConfig.cmake:156 (message):
  Found OpenCV Windows Pack but it has no binaries compatible with your
  configuration.

  You should manually point CMake variable OpenCV_DIR to your build of OpenCV
  library.
Call Stack (most recent call first):
  CMakeLists.txt:4 (find_package)


CMake Error at CMakeLists.txt:4 (find_package):
  Found package configuration file:

    C:/OpenCV34/opencv/build/OpenCVConfig.cmake

  but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be
  NOT FOUND.


-- Configuring incomplete, errors occurred!
See also "E:/Code/cmake/displayopencv/CMakeFiles/CMakeOutput.log".

I cannot figure out what's wrong, it selected the OpenCV arch incorrect too. I have 64-bit OpenCV installed at that location,

C:\OpenCV34\opencv\build>dir
 Volume in drive C has no label.
 Volume Serial Number is E8D4-7C0B

 Directory of C:\OpenCV34\opencv\build

01-09-2018  11:47    <DIR>          .
01-09-2018  11:47    <DIR>          ..
01-09-2018  11:49    <DIR>          bin
01-09-2018  11:47    <DIR>          etc
01-09-2018  11:47    <DIR>          include
01-09-2018  11:47    <DIR>          java
11-04-2018  07:48             2,275 LICENSE
29-08-2018  16:05               433 OpenCVConfig-version.cmake
29-08-2018  16:05             5,728 OpenCVConfig.cmake
01-09-2018  11:47    <DIR>          python
01-09-2018  11:47    <DIR>          x64
               3 File(s)          8,436 bytes
               8 Dir(s)  93,118,218,240 bytes free

C:\OpenCV34\opencv\build>dir x64
 Volume in drive C has no label.
 Volume Serial Number is E8D4-7C0B

 Directory of C:\OpenCV34\opencv\build\x64

01-09-2018  11:47    <DIR>          .
01-09-2018  11:47    <DIR>          ..
01-09-2018  11:47    <DIR>          vc14
01-09-2018  11:47    <DIR>          vc15
               0 File(s)              0 bytes
               4 Dir(s)  93,118,218,240 bytes free

How do I fix this issue and use cmake with OpenCV on Windows 10 computer?

Error using cmake on Windows with Visual Studio 2017 and OpenCV 3.4.3

Hi,

I am following this page from OpenCV Docs to use cmake with OpenCV.

This is my file structure,

- displayopencv\
-- CMakeLists.txt
-- DisplayImage.cpp

CMakeLists.txt contains,

cmake_minimum_required(VERSION 2.8)
set(OpenCV_DIR C:/OpenCV34/opencv/build)
project( DisplayImage )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

I run cmake . in this directory inside command prompt and get the following error,

-- Selecting Windows SDK version 10.0.16299.0 to target Windows 10.0.17134.
-- OpenCV ARCH: x86
-- OpenCV RUNTIME: vc14
-- OpenCV STATIC: OFF
CMake Warning at C:/OpenCV34/opencv/build/OpenCVConfig.cmake:156 (message):
  Found OpenCV Windows Pack but it has no binaries compatible with your
  configuration.

  You should manually point CMake variable OpenCV_DIR to your build of OpenCV
  library.
Call Stack (most recent call first):
  CMakeLists.txt:4 (find_package)


CMake Error at CMakeLists.txt:4 (find_package):
  Found package configuration file:

    C:/OpenCV34/opencv/build/OpenCVConfig.cmake

  but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be
  NOT FOUND.


-- Configuring incomplete, errors occurred!
See also "E:/Code/cmake/displayopencv/CMakeFiles/CMakeOutput.log".

I cannot figure out what's wrong, it selected the OpenCV arch incorrect too. I have 64-bit OpenCV installed at that location,

C:\OpenCV34\opencv\build>dir
 Volume in drive C has no label.
 Volume Serial Number is E8D4-7C0B

 Directory of C:\OpenCV34\opencv\build

01-09-2018  11:47    <DIR>          .
01-09-2018  11:47    <DIR>          ..
01-09-2018  11:49    <DIR>          bin
01-09-2018  11:47    <DIR>          etc
01-09-2018  11:47    <DIR>          include
01-09-2018  11:47    <DIR>          java
11-04-2018  07:48             2,275 LICENSE
29-08-2018  16:05               433 OpenCVConfig-version.cmake
29-08-2018  16:05             5,728 OpenCVConfig.cmake
01-09-2018  11:47    <DIR>          python
01-09-2018  11:47    <DIR>          x64
               3 File(s)          8,436 bytes
               8 Dir(s)  93,118,218,240 bytes free

C:\OpenCV34\opencv\build>dir x64
 Volume in drive C has no label.
 Volume Serial Number is E8D4-7C0B

 Directory of C:\OpenCV34\opencv\build\x64

01-09-2018  11:47    <DIR>          .
01-09-2018  11:47    <DIR>          ..
01-09-2018  11:47    <DIR>          vc14
01-09-2018  11:47    <DIR>          vc15
               0 File(s)              0 bytes
               4 Dir(s)  93,118,218,240 bytes free

How do I fix this issue and use cmake with OpenCV on Windows 10 computer?

Edit 1:

I changed CMakeLists.txt and changed set(OpenCV_DIR... line to this,

SET("OpenCV_DIR" "C:/OpenCV34/opencv/build/x64/vc15/lib")

After this,

E:\Code\cmake\DisplayImage>cmake .
-- Selecting Windows SDK version 10.0.16299.0 to target Windows 10.0.17134.
-- Found OpenCV: C:/OpenCV34/opencv/build (found version "3.4.3")
-- Configuring done
-- Generating done
-- Build files have been written to: E:/Code/cmake/DisplayImage

It seems to work but I cannot seem to compile the SLN generated in Visual Studio 2017. The default configuration was Win32, I copied the settings to x64 but I get this error

Error   LNK1112 module machine type 'x64' conflicts with target machine type 'x86'  DisplayImage    E:\Code\cmake\DisplayImage\x64\Debug\DisplayImage.obj   1