c++qtopencvqt5undefined-reference

Use OpenCV in qt qmake project: undefined reference


I want to use OpenCV in a QT qmake project. The vrsions are opencv 4.9.0 and QT 5.15.2(MSV 2019,64bit).

.pro file

INCLUDEPATH += C:/opencv/build/include
LIBS += -LC:/opencv/build/x64/vc16/lib \
        -lopencv_world490

mainwindow.cpp

#include <opencv2/opencv.hpp>
using namespace cv; 

...
cv::Mat mat; 
...

After build, I get the error: undefined reference to cv::Mat::Mat()

Hint: my project is a widget program with qmake (not cmake).


Solution

  • My problem finally resolved with the following actions:

    1. I used 'OpenCV 4.5.2' (downloded from https://github.com/huihut/OpenCV-MinGW-Build) .

    2. In the .cpp file replaced #include <opencv2/highgui.hpp> By '''#include <opencv2/highgui/highgui.hpp>'''

    3. Copy .dll files (in the bin folder of opencv) to my project debug/release folder.

    Hope this helps others too.