C++ OpenCV - DLL 丢失,但不是?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2694994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenCV - DLL missing, but it's not?
提问by charles-22
I am trying just a basic program with OpenCV with the following code:
我正在尝试使用以下代码使用 OpenCV 的基本程序:
#include "cv.h"
#include "highgui.h"
int main()
{
IplImage* newImg;
newImg = cvLoadImage("~/apple.bmp", 1);
cvNamedWindow("Window", 1);
cvShowImage("Window", newImg);
cvWaitKey(0);
cvDestroyWindow("Window");
cvReleaseImage(&newImg);
return 0;
}
When I run this, I get
当我运行这个时,我得到
The program can't start because libcxcore200.dll is missing from your computer. Try reinstalling the program to fix this problem.
程序无法启动,因为您的计算机缺少 libcxcore200.dll。尝试重新安装程序以解决此问题。
However, I can see this DLL. It exists. I have added the following to the input dependencies for my linker
但是,我可以看到这个 DLL。它存在。我已将以下内容添加到链接器的输入依赖项中
C:\OpenCV2.0\lib\libcv200.dll.a C:\OpenCV2.0\lib\libcvaux200.dll.a C:\OpenCV2.0\lib\libcxcore200.dll.a C:\OpenCV2.0\lib\libhighgui200.dll.a
C:\OpenCV2.0\lib\libcv200.dll.a C:\OpenCV2.0\lib\libcvaux200.dll.a C:\OpenCV2.0\lib\libcxcore200.dll.a C:\OpenCV2.0\lib \libhighgui200.dll.a
What gives? I'm using visual studio 2008.
是什么赋予了?我正在使用 Visual Studio 2008。
When I link the .dll files instead of .dll.a files, I get
当我链接 .dll 文件而不是 .dll.a 文件时,我得到
fatal error LNK1107:invalid or corrupt file: cannot read at 0x3F8 libcv200.dll
致命错误 LNK1107:无效或损坏的文件:无法读取 0x3F8 libcv200.dll
回答by skoeberl
I followed instructions on http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010but was still stuck on exactly the same problem, so here's how I resolved it.
我按照http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010 上的说明进行操作,但仍然遇到完全相同的问题,所以这是我解决的方法。
Fetched MSVC 2010 express edition.
Fetched Win 32 OpenCV 2.2 binaries and installed in default location.
Created new project.
Project setup
Project -> OpenCV_Helloworld Properties...Configuration Properties -> VC++ Directories
Include Directories... add:
C:\OpenCV2.2\include\;
Library Directories... add:
C:\OpenCV2.2\lib;C:\OpenCV2.2\bin;
Source Directories... add:
C:\OpenCV2.2\modules\calib3d\src;C:\OpenCV2.2\modules\contrib\src;C:\OpenCV2.2\modules\core\src;C:\OpenCV2.2\modules\features2d\src;C:\OpenCV2.2\modules\flann\src;C:\OpenCV2.2\modules\gpu\src;C:\OpenCV2.2\modules\gpu\src;C:\OpenCV2.2\modules\highgui\src;C:\OpenCV2.2\modules\imgproc\src;C:\OpenCV2.2\modules\legacy\src;C:\OpenCV2.2\modules\ml\src;C:\OpenCV2.2\modules\objdetect\src;C:\OpenCV2.2\modules\video\src;
Linker -> Input -> Additional Dependencies...
For Debug Builds... add:
opencv_calib3d220d.lib;opencv_contrib220d.lib;opencv_core220d.lib;opencv_features2d220d.lib;opencv_ffmpeg220d.lib;opencv_flann220d.lib;opencv_gpu220d.lib;opencv_highgui220d.lib;opencv_imgproc220d.lib;opencv_legacy220d.lib;opencv_ml220d.lib;opencv_objdetect220d.lib;opencv_video220d.lib;
获取 MSVC 2010 速成版。
获取 Win 32 OpenCV 2.2 二进制文件并安装在默认位置。
创建了新项目。
项目设置
项目 -> OpenCV_Helloworld 属性...配置属性 -> VC++ 目录
包括目录...添加:
C:\OpenCV2.2\include\;
库目录...添加:
C:\OpenCV2.2\lib;C:\OpenCV2.2\bin;
源目录...添加:
C:\OpenCV2.2\modules\calib3d\src;C:\OpenCV2.2\modules\contrib\src;C:\OpenCV2.2\modules\core\src;C:\OpenCV2.2\modules\features2d\src;C:\OpenCV2.2\modules\flann\src;C:\OpenCV2.2\modules\gpu\src;C:\OpenCV2.2\modules\gpu\src;C:\OpenCV2.2\modules\highgui\src;C:\OpenCV2.2\modules\imgproc\src;C:\OpenCV2.2\modules\legacy\src;C:\OpenCV2.2\modules\ml\src;C:\OpenCV2.2\modules\objdetect\src;C:\OpenCV2.2\modules\video\src;
链接器 -> 输入 -> 附加依赖项...
对于调试版本...添加:
opencv_calib3d220d.lib;opencv_contrib220d.lib;opencv_core220d.lib;opencv_features2d220d.lib;opencv_ffmpeg220d.lib;opencv_flann220d.lib;opencv_gpu220d.lib;opencv_highgui220d.lib;opencv_imgproc220d.lib;opencv_legacy220d.lib;opencv_ml220d.lib;opencv_objdetect220d.lib;opencv_video220d.lib;
At this point I thought I was done, but ran into the problem you described when running the exe in debug mode. The final step is obvious once you see it, select:
此时我以为我已经完成了,但是在调试模式下运行exe时遇到了您描述的问题。看到最后一步就很明显了,选择:
Linker -> General ... Set 'Use Library Dependency Inputs' to 'Yes'
链接器 -> 常规 ... 将“使用库依赖项输入”设置为“是”
Hope this helps.
希望这可以帮助。
回答by YOU
Just add C:\OpenCV2.0\bin
into your PATHenvironment variable
只需添加C:\OpenCV2.0\bin
到您的PATH环境变量中
or
或者
When you install OpenCV,
安装 OpenCV 时,
Choose the option, Add OpenCV to the system PATH for current user
which is not default one
选择该选项,Add OpenCV to the system PATH for current user
这不是默认选项
回答by Steven Du
Just for your information,after add the "PATH",for my win7 i need to reboot it to get it work.
仅供参考,在添加“PATH”后,对于我的 win7,我需要重新启动它才能使其工作。
回答by Sabri Mevi?
In Visual Studio 2013 you need to add this to the Environment Variables
and then Restart
your pc. This is the path where .dll file located in.
在Visual Studio 2013,你需要它添加到Environment Variables
,然后Restart
你的电脑。这是 .dll 文件所在的路径。
回答by Opencv_newbie
I have had numerous problems with opencv and only succeded after a gruesome 4-6 months. This is the last problem I have had, but all of the above didn't work. What worked for me was just copying and pasting the opencv_core2*.dll (and opencv_highgui2*.dll which it will ask for since you included this as well) into the release (or debug folder - I'm assuming. Haven't tested this) folder of your project, where your application file is.
我在使用 opencv 时遇到了很多问题,并且仅在令人毛骨悚然的 4-6 个月后才成功。这是我遇到的最后一个问题,但以上所有方法都不起作用。对我有用的只是将 opencv_core2*.dll(以及 opencv_highgui2*.dll,因为您也包含它而要求)复制并粘贴到发行版(或调试文件夹 - 我假设。还没有测试过这个) 项目的文件夹,您的应用程序文件所在的文件夹。
Hope this helps!
希望这可以帮助!
回答by Farzan
You just need to add the folder of the needed dll file (or files) to your system "Environment Variables" in "Path". Your problem will 100% be resolved. I had this problem too.
您只需要将所需 dll 文件(或多个文件)的文件夹添加到系统“路径”中的“环境变量”中。您的问题将 100% 得到解决。我也有这个问题。
回答by somebody
just open the bin folder and copy and paste the .dll files to the folder you are working in..it should fix the problem
只需打开 bin 文件夹并将 .dll 文件复制并粘贴到您正在使用的文件夹中..它应该可以解决问题
回答by kenny
As to @Marc's answer, I don't think VC uses the path from the OS. Did you add the path to VC's library paths. I usually add the DLLs to the project and copy if newer on the build and that works very well for me.
至于@Marc 的回答,我不认为 VC 使用来自操作系统的路径。您是否将路径添加到 VC 的库路径。我通常将 DLL 添加到项目中,并在构建中更新时进行复制,这对我来说非常有效。
回答by phoenix
you can find the opencv_core248 and other dlls in opencv\build\x86\vc12\bin folder. Just copy the dlls you require into system32 folder. And your app should start working in a flash ! Hope it helps.
您可以在 opencv\build\x86\vc12\bin 文件夹中找到 opencv_core248 和其他 dll。只需将您需要的 dll 复制到 system32 文件夹中即可。您的应用程序应该立即开始工作!希望能帮助到你。
回答by cecil merrel aka bringrainfire
This might be like resurrecting a dead horse. But just so it's out there, the reason why the answer to these types of questions to simply put dll's into the system32 folder is because that folder is in the os's system path.
这可能就像复活一匹死马。但就这样,这些类型的问题的答案只是将 dll 放入 system32 文件夹的原因是因为该文件夹位于操作系统的系统路径中。
It's actually best practice to provide the os with a path link.
为操作系统提供路径链接实际上是最佳实践。
With windows 10
使用 Windows 10
- open up file explorer
- right click on "this pc" and select "properties"
- Now in the "Control Panel\System and Security\System" window that comes up, click on "Advanced System Settings" from the left hand panel.
- At the bottom of the next window, click on the "Environment Variables" button.
- On the next window, there are two panels, the top one is for modifying variables to the current user, and the bottom panel is for modifying variables to the system. On the bottom panel, find the variable "Path" and click it to select it, then click on the "edit" button.
- Here you can then create, edit, delete, or update the different paths for the system. For example, to add mingw32-make to the system so you can access that command via command prompt, click new, then paste in the path to the bin. Example path, "D:\Qt\Tools\mingw730_64\bin", no quotation marks nor additional whitespaces.
- Click ok on all the windows so that the changes are saved, then rebootyour computer for the changes to be loaded.
- 打开文件浏览器
- 右键单击“此电脑”并选择“属性”
- 现在在出现的“控制面板\系统和安全\系统”窗口中,单击左侧面板中的“高级系统设置”。
- 在下一个窗口的底部,单击“环境变量”按钮。
- 在下一个窗口中,有两个面板,顶部是修改当前用户的变量,底部的面板是修改系统的变量。在底部面板上,找到变量“Path”并单击它以将其选中,然后单击“编辑”按钮。
- 然后,您可以在此处创建、编辑、删除或更新系统的不同路径。例如,要将 mingw32-make 添加到系统以便您可以通过命令提示符访问该命令,请单击新建,然后将路径粘贴到 bin。示例路径,“D:\Qt\Tools\mingw730_64\bin”,没有引号,也没有额外的空格。
- 在所有窗口上单击确定以保存更改,然后重新启动计算机以加载更改。