Cmake: incorrect OpenCV path generation

My environment:

  • Windows 7 64
  • CMake 2.8.10.2
  • Opencv 2.4.4
  • Visual Studio Express 2012

My problem:

I have a CMake project using Opencv and built in under vs11. Everything works with preinstalled binaries (from c: / opencv / build in my case). I wanted to change some parameters of Opencv, so I had to build it from the source (in c: / opencv / build2). Everything is built-in and installed correctly in c: / opencv / built2, but I have this error from my IDE:

error LNK1104: cannot open file 'C: \ opencv \ build2 \ lib \ Debug \ Debug \ opencv_objdetect244d.lib'

In fact, there is no such file. It seems my CMakeLists.txt script corrupts the OpenCV_LIBS variable by adding the Debug \ (or Release) subdirectory for each call:

MESSAGE ( STATUS "OpenCV_LIBS = ${OpenCV_LIBS}" ) FIND_PACKAGE ( OpenCV COMPONENTS core highgui imgproc objdetect REQUIRED ) MESSAGE ( STATUS "OpenCV_LIBS = ${OpenCV_LIBS}" ) FIND_PACKAGE ( OpenCV COMPONENTS core highgui imgproc objdetect REQUIRED ) MESSAGE ( STATUS "OpenCV_LIBS = ${OpenCV_LIBS}" ) FIND_PACKAGE ( OpenCV COMPONENTS core highgui imgproc objdetect REQUIRED ) MESSAGE ( STATUS "OpenCV_LIBS = ${OpenCV_LIBS}" ) 

outputs:

OpenCV_LIBS = debug; C: /opencv/build2/lib/Debug/opencv_contrib244d.lib; (...)

OpenCV_LIBS = debug; C: /opencv/build2/lib/Debug/Debug/opencv_objdetect244d.lib; (...)

OpenCV_LIBS = debug; C: /opencv/build2/lib/Debug/Debug/Debug/opencv_objdetect244d.lib; (...)

OpenCV_LIBS = debug; C: /opencv/build2/lib/Debug/Debug/Debug/Debug/opencv_objdetect244d.lib; (...)

OpenCV_LIBS = debug; C: /opencv/build2/lib/Debug/Debug/Debug/Debug/Debug/opencv_objdetect244d.lib; (...)

Am I doing something wrong with my CMake scripts?

+4
source share
1 answer

OK, it seems that OpenCVConfig.cmake distorts the OpenCVConfig.cmake variable when it is turned on several times with successive calls to FIND_PACKAGE() .

A quick fix is ​​to add FORCE to lines 91-94 in OpenCVConfig.cmake :

 # Provide the libs directories to the caller set(OpenCV_LIB_DIR_OPT "C:/opencv/build2/lib" CACHE PATH "Path where release OpenCV libraries are located" FORCE) set(OpenCV_LIB_DIR_DBG "C:/opencv/build2/lib" CACHE PATH "Path where debug OpenCV libraries are located" FORCE) set(OpenCV_3RDPARTY_LIB_DIR_OPT "C:/opencv/build2/3rdparty/lib" CACHE PATH "Path where release 3rdpaty OpenCV dependencies are located" FORCE) set(OpenCV_3RDPARTY_LIB_DIR_DBG "C:/opencv/build2/3rdparty/lib" CACHE PATH "Path where debug 3rdpaty OpenCV dependencies are located" FORCE) 

The file to change is C:\opencv\cmake\templates\OpenCVConfig.cmake.in .

Then rebuild / recompile / reinstall OpenCV and then your own project.

+1
source

All Articles