4

我的环境:

  • 视窗 7 64
  • CMake 2.8.10.2
  • Opencv 2.4.4
  • 视觉工作室速成版 2012

我的问题:

我有一个使用 Opencv 并在 vs11 下构建的 CMake 项目。一切都适用于预先构建的二进制文件(在我的例子中来自 c:/opencv/build)。我想更改一些 Opencv 设置,所以我必须从源代码(在 c:/opencv/build2 中)构建它。一切都在 c:/opencv/built2 中正确构建和安装,但我的 IDE 出现此错误:

错误 LNK1104:无法打开文件 'C:\opencv\build2\lib\Debug\Debug\opencv_objdetect244d.lib'

确实,没有这样的文件。似乎我的 CMakeLists.txt 脚本通过在每次调用中添加 Debug\(或 Release)子目录来破坏 OpenCV_LIBS 变量:

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}" )

输出:

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

OpenCV_LIBS = 调试;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;(...)

我的 CMake 脚本有问题吗?

4

1 回答 1

1

好的,似乎在连续调用中多次包含变量时OpenCVConfig.cmake会破坏变量。OpenCV_LIBSFIND_PACKAGE()

一个快速的解决方法是添加FORCE到第91-94OpenCVConfig.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)

要修改的文件是C:\opencv\cmake\templates\OpenCVConfig.cmake.in.

然后重建/重新编译/重新安装 OpenCV,然后是你自己的项目。

于 2013-03-08T13:41:03.573 回答