0

I have been following this tutorial and I did all of them carefully. But afterwards I ran the simple code:

I saw this error and how can I fix it?

Tutorial: https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows

I removed qt and opencv and I used the version that used in the tutorial that I mentioned but I got the same error.

And also I added "img.jpg" to my project directory.

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;
using namespace cv;
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    Mat image = imread("img.jpg", 1);
    namedWindow("My Image");
    imshow("My Image", image);
    waitKey(0);    
}

MainWindow::~MainWindow()
{
    delete ui;
}

and I added them to my .pro file:

INCLUDEPATH += C:\OpenCV-Qt\build\install\include
LIBS += C:\OpenCV-Qt\build\bin\libopencv_core320.dll.a
LIBS += C:\OpenCV-Qt\build\bin\libopencv_highgui320.dll
LIBS += C:\OpenCV-Qt\build\bin\libopencv_imgcodecs320.dll
LIBS += C:\OpenCV-Qt\build\bin\libopencv_imgproc320.dll
LIBS += C:\OpenCV-Qt\build\bin\libopencv_features2d320.dll
LIBS += C:\OpenCV-Qt\build\bin\libopencv_calib3d320.dll

I expect to create a window and show the image in it but I get the error:

C:\OpenCV-Qt\build\bin\libopencv_core320.dll:-1: error: LNK1107: invalid or corrupt file: cannot read at 0x3D0

Peter G.
  • 14,786
  • 7
  • 57
  • 75
  • 3
    You don't link to dlls. You link to import libraries and put the dlls in a folder in your PATH environment variable or the same folder as the executable – drescherjm Dec 21 '18 at 14:10
  • 1
    I don't know why the tutorial at the Qt site has this fundamental mistake. Edit: I see the instructions are for `mingw` not `Visual Studio`. You appear to be using Visual Studio. – drescherjm Dec 21 '18 at 14:13
  • 1
    Even with mingw, you still need to link against the .lib files. – Matthieu Brucher Dec 21 '18 at 14:25
  • Thanks. I was not sure about that. – drescherjm Dec 21 '18 at 14:29
  • In the case of mingw I now expect this was just a typo in the tutorial. For all of the dlls listed it should be `dll.a`. However these instructions and binaries will not work with Visual Studio. – drescherjm Dec 21 '18 at 14:33

0 Answers0