1

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.

"missing libgcc_s_dw2-1.dll" message window

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

console, error code window

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

Community
  • 1
  • 1
Zhi Lu
  • 527
  • 5
  • 22
  • [Updated] Code::Block can run correctly if there is no OpenCV code in the code. I made a test where I add "cv::Mat impic = imread("kindle-fire-hd.jpg"); in a blank main() function. It shows the same problem. So, I guess that this is caused by the linking with the OpenCV library? – Zhi Lu Oct 03 '12 at 02:31
  • [Updated] I have solved this question. – Zhi Lu Oct 04 '12 at 00:13

2 Answers2

4

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

Community
  • 1
  • 1
Zhi Lu
  • 527
  • 5
  • 22
  • I have been trying to figure out how to add the system path for this and I cannot figure it out. I think it would add to this answer if you included an example of what the path name and directory should be. I tried it with a random name and the path to the file I put the dlls in and it didnt work. Is that just something wrong with my pc or am I adding the path wrong? Thanks! – DivideByZero Nov 29 '14 at 07:13
1

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.

M4rc
  • 473
  • 2
  • 13
  • yes, -static-libgcc, -static- or -static-libg++ cannot run correctly because I had tried them before. – Zhi Lu Oct 03 '12 at 02:04
  • I just downloaded them from a google'd site, and put them in the directory with it, and voila. I'm sure there may be a way to remove the linking, it's just not what people claim it is. – M4rc Oct 03 '12 at 02:07
  • 1
    Saying what to do with the dlls would improve this answer. It is still relevant even today! (2 years later) – DivideByZero Dec 01 '14 at 04:04