OpenCV - DLL missing, but it's not?

2019-01-13 10:11发布

问题:

I am trying just a basic program with OpenCV with the following code:

#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.

However, I can see this DLL. It exists. I have added the following to the input dependencies for my linker

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.

When I link the .dll files instead of .dll.a files, I get

fatal error LNK1107:invalid or corrupt file: cannot read at 0x3F8 libcv200.dll

回答1:

I followed instructions on http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010 but was still stuck on exactly the same problem, so here's how I resolved it.

  1. Fetched MSVC 2010 express edition.

  2. Fetched Win 32 OpenCV 2.2 binaries and installed in default location.

  3. Created new project.

  4. 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;
    

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:

Linker -> General ... Set 'Use Library Dependency Inputs' to 'Yes'

Hope this helps.



回答2:

Just add C:\OpenCV2.0\bin into your PATH environment variable

or

When you install OpenCV,

Choose the option, Add OpenCV to the system PATH for current user which is not default one



回答3:

Just for your information,after add the "PATH",for my win7 i need to reboot it to get it work.



回答4:

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.

Hope this helps!



回答5:

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.



回答6:

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.



回答7:

just open the bin folder and copy and paste the .dll files to the folder you are working in..it should fix the problem



回答8:

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.



回答9:

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.



回答10:

The ".a" at the end of your DLL files is a problem, and those are there because you didn't use CMAKE to build OpenCV 2.0. Additionally you do not link to the DLL files, you link to the library files, and again, the reason you do not see the correct library files is because you didn't use CMAKE to build OpenCV 2.0. If you want to use OpenCV 2.0 you must build it for it to work correctly in Visual Studio. If you do not want to build it then I would suggest downgrading to OpenCV 1.1pre, it comes pre-built and is much more forgiving in Visual Studio.

Another option (and the one I would recommend) is to abandon OpenCV and go with EmguCV. I have been playing with OpenCV for about a year and things got much easier when I switched to EmguCV because EmguCV works with .NET, so you can use a language like C# that does not come with all the C++ baggage of pointers, header files, and memory allocation problem.

And as for the question of 64bit vs. 32bit, OpenCV does not officially support 64bit. To be on the safe side open your project properties and change the "Platform Target" under the "Build" tab from "Any CPU" to "X86". This should be done any time you do anything with OpenCV, even if you are using a wrapper like EmguCV.



回答11:

Copy all .dll from /bin in System32



回答12:

Just copy the .dll files to C:\windows\system32\



回答13:

No need to do any of that. It is a visual studio error.

just go here: http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=31354

and download the appropriate fix for your computer's OS

close visual studio, run the fix and then restart VS

The code should run without any error.



标签: c++ opencv