重构代码后链接到OpenCV时出错

时间:2012-02-20 11:55:29

标签: opencv cmake

我刚刚重组了我的代码(之前有效),现在我运行可执行文件时收到错误消息:The program can't start because opencv_core230d.dll is missing from your computer.错误是准确的,我只有OpenCV的.lib库文件,但它以前工作过,我不认为这应该是个问题,不是吗?

cmake文件的摘录是:

FIND_PACKAGE( OpenCV REQUIRED )

# Define LIBRARY and SRC_FILES to create my library
add_library(${LIBRARY} ${SRC_FILES})
target_link_libraries(${LIBRARY} ${OpenCV_LIBS} )

# Define appName and appFile to create application,
# and link to my library and OpenCV
add_executable(${appName} ${appFile})
target_link_libraries(${appName} ${LIBRARY} ${OpenCV_LIBS})

我做了什么明显错误,或者还有什么可能导致此错误?


编辑:我现在将这个问题简化为一个最小的例子。在一个目录测试中,我有两个文件:testApp.cpp和CMakeLists.txt,如下所示:

testApp.cpp

#include <opencv2/opencv.hpp>

int main(int argc, char* argv[])
{
    cv::namedWindow("Test");
    cv::waitKey(0);
    cv::destroyAllWindows();

    return 0;
}

的CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
project(test)

FIND_PACKAGE( OpenCV REQUIRED )

add_executable(appName testApp.cpp)
target_link_libraries(appName ${OpenCV_LIBS})
message(STATUS "Linking testapp to: ${OpenCV_LIBS}")

出现错误:opencv_highgui230d.dll is missing.

2 个答案:

答案 0 :(得分:1)

问题是环境变量 PATH 没有指向OpenCV的DLL所在的位置。在OpenCV目录中搜索,如果找不到,则需要重新安装OpenCV。

答案 1 :(得分:0)

似乎这是一个常见问题,只需要进行更多研究。为了解决这个问题,我刚刚将OpenCV / bin目录添加到PATH环境变量中。仍然不确定为什么它以前工作...但