VideoCapture compile error

My code in Qt

LIBS += -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_highgui

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

using namespace cv;

Mat frame;
VideoCapture cap = VideoCapture(0);
 while(1)
{
     //cap.read(frame);
    cap>>frame;
    imshow("image", frame);
 }

When I build I get

/usr/bin/ld: main.o: undefined reference to symbol ‘_ZN2cv12VideoCaptureD1Ev’
/usr/bin/ld: //usr/lib/arm-linux-gnueabihf/libopencv_videoio.so.3.2: error adding symbols: >DSO missing from command line
collect2: error: ld returned 1 exit status

What may be a problem?

same problem as in your last question – you’re missing a library

-lopencv_videoio

also, for clarity, you should

#include <opencv2/videoio.hpp>

explicitly (it’s still in the highgui header for historic reasons)

(rule of thumb - you need a library for each module header you include …)

1 Like

Thank you so much! )