重构代码后链接到 OpenCV 时出错
我刚刚重新组织了我的代码(之前有效),现在在运行可执行文件时收到一条错误消息: 程序无法启动,因为您的计算机中缺少 opencv_core230d.dll。
错误是准确的,我只有 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})
我是否做了任何明显错误的事情,或者还有什么可能导致此错误?
编辑:我现在已将这个问题简化为一个最小的示例。在一个目录 test 中,我有两个文件: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 丢失。
I've just reorganised my code (which worked before) and am now getting an error message when I run my executable: The program can't start because opencv_core230d.dll is missing from your computer.
The error is accurate, I only have .lib library files for OpenCV, but it worked before and I don't think this should be a problem, should it?
An extract from the cmake file is:
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})
Am I doing anything obviously wrong, or what else might cause this error?
EDIT: I've now reduced this problem to a minimal example. Inside one directory test I have two files: testApp.cpp and CMakeLists.txt as follows:
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}")
With the error as before: opencv_highgui230d.dll is missing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是环境变量PATH没有指向OpenCV的DLL所在的位置。在 OpenCV 目录中搜索,如果找不到,则需要重新安装 OpenCV。
The problem is that the environment variable PATH does not point to the location where OpenCV's DLLs reside. Search inside OpenCV directories and if you can't find it you'll need to reinstall OpenCV.
似乎这是一个常见问题,只需要进行更多研究。为了解决这个问题,我只是将 OpenCV/bin 目录添加到 PATH 环境变量中。但仍然不确定为什么它之前可以工作......
Seems this is a common problem which simply needed some more research. To fix, I just added the OpenCV/bin directory to the PATH environmental variable. Still not sure why it was working previously though...