Search code examples
c++opencvmingw-w64

Entry point errors when running OpenCV projects with MingW


I have installed MingW C++ compiler on Windows 10. I built the OpenCV libraries successfully. Then I wrote a test project as follows.

#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

using namespace std;
using namespace cv;

int main()
{
    Mat input = imread("lenna.jpg", IMREAD_GRAYSCALE);
    //Mat input(100, 200, CV_8UC(1), Scalar(100));

    if (input.empty())
    {
        cout << "Image is empty" << endl;
        return -1;
    }

    unsigned short rows = input.rows;
    unsigned short cols = input.cols;


    for (unsigned short i = 0; i < cols / 4; i++)
        for (unsigned short j = 0; j < rows / 4; j++)
            input.at<uchar>(j, i) = 0;

    const string wnd = "input";

    namedWindow(wnd, WINDOW_NORMAL);
    imshow(wnd, input);

    waitKey();
    destroyWindow(wnd);

    return 0;
}

The compilation is done successfully but if I run it, the following errors occur in the given order (from top to bottom one by one).

enter image description here

My task.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "\"${env:WINLAB_CPP}\\g++.exe\"",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-I",
                "c:\\opencv_z\\build\\include",
                "-L",
                "c:\\opencv_z\\releases\\bin",
                "-llibopencv_core451",
                "-llibopencv_highgui451",
                "-llibopencv_imgcodecs451",
                "-llibopencv_imgproc451",
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Is there any hint to solve it?


Solution

  • The culprit is:

    There are two 64-bit libstdc++-6.dll files in my PATH. The older one unfortunately is on the top so any request to 64b-bit libstdc++-6.dll will be bounded to the top one.

    As a result, my applications that need the new one gets crashed. Swapping them solves the problem.

    Using 32-bit version of MinGW can solve this issue as well, but it is a very controversial option!