0

When declaring cv::Mat mat on my Header file. I encounter an error : "Unresolved External Symbol"

enter image description here

I included these already:

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

Versions: QT 4.2.0 | Open CV 4.1.0

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
TerribleDog
  • 1,237
  • 1
  • 8
  • 31

2 Answers2

0

including headers is not enough in most cases (only where the headers use non standard features to tell the compiler which library to link).

You need to tell the linker to add the corresponding .lib files. In Visual Studio you can do this in the project properties -> Linker -> Additional Libraries. In OpenCV you'll probably find those libraries close to where the headers are if you downloaded a prepuilt version. The .lib files need to match the compiler version you are using to work, eg. to work with a 2019 compiler they need to be build with 2017 or 2015.

Reinhold
  • 546
  • 1
  • 3
  • 14
0

First of all be sure about the installation of opencv. Check it using:

pkg-config --modversion opencv

Then add the followings to your .pro file:

 INCLUDEPATH += /usr/local/include/opencv // for path

 LIBS += `pkg-config --cflags --libs opencv` // for libraries

When these are done opencv libraries should work in any cpp file in Qt

Yunus Temurlenk
  • 4,085
  • 4
  • 18
  • 39