OpenCV program cannot run because of missing “libg

2019-06-02 08:06发布

问题:

I write a simple OpenCV program that tries to open an image "kindle-fire-hd.jpg" in the same directory. The IDE is Code::Block and the version OpenCV is 2.4.2 and the compiler is MinGW which is attached as the component of Code::Block. The code is shown here:

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
  Mat im = imread(argc == 2 ? argv[1] : "kindle-fire-hd.jpg", 1);
  if (im.empty())
  {
    cout << "Cannot open image!" << endl;
    return -1;
  }

  imshow("image", im);
  waitKey(0);

  return 0;
}

It can be built and compiled correctly (without any error and warning messages) and I have configured the Code::Block as that said in Getting started with OpenCV 2.4 and MinGW on Windows 7 .

However, when I "run" this program. it shows a "missing libgcc_s_dw2-1.dll" message.

And, when I click the "OK" button, the console window shows the following message:

I tried to search the related Questions on stackoverflow but all their solutions cannot fix this problem. Thanks.

回答1:

Finally, I fix this problem!

This reason that causes this "missing dll" problem is the MinGW compiler attached with the Code::Block is not complete. So, you need to download the required DLL files to the directory "C:\Program Files (x86)\CodeBlocks\MinGW\libexec\gcc\mingw32\4.4.1" which you also need to add the path of this directory to the system PATH environment variable.

In this case, I download two DLL files: libgcc_s_dw2-1.dll and libstdc++-6.dll even if there is only one missing error message about libgcc_s_dw2-1.dll. If you forget the second one, libstdc++-6.dll, you will get another missing message when run the program.

The first dll, libgcc_s_dw2-1.dll, can be fond at the question Where Can I Get libgcc_s_dw2-1.dll?, in which the download link is listed in the selected answer by the author rodrigo. Thanks the guy!

The second dll, libstdc++-6.dll, can be downloaded at http://sourceforge.net/projects/mingw/files/MinGW/Base/gcc/Version4/gcc-4.6.2-1/libstdc%2B%2B-4.6.2-1-mingw32-dll-6.tar.lzma/download



回答2:

For what ever reason Code::blocks doesn't ship with that DLL, though it can be downloaded through a google'd site. You will probably need one other DLL, which would be libstdc++6.dll

People will inform you to link -static-libgcc, -static- or -static-libg++ in linking options, at least with my version (And presumably yours) it will not resolve the issue unless I'm doing it wrong, which is plausible.