Important: Please read the Qt Code of Conduct -

opencv error: undefined reference to `cv::VideoCapture::VideoCapture()'

  • I try to use opencv3.2 with qt5.7,but I always get those erros:
    /home/hunter/cameraTt/main.cpp:17: error: undefined reference to cv::VideoCapture::open(int)' /home/hunter/cameraTt/main.cpp:18: error: undefined reference tocv::VideoCapture::isOpened() const'
    /home/hunter/cameraTt/main.cpp:20: error: undefined reference to cv::VideoCapture::get(int) const' /home/hunter/cameraTt/main.cpp:22: error: undefined reference tocv::VideoCapture::operator>>(cv::Mat&)'
    /home/hunter/cameraTt/main.cpp:24: error: undefined reference to `cv::VideoWriter::VideoWriter()'

    INCLUDEPATH += /usr/local/include/opencv2

    LIBS += /usr/local/lib/ \

          /usr/local/lib/ \


    #include "mainwindow.h"
    #include <QApplication>
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    //using namespace cv;
    int main(int argc, char *argv[])
    QApplication a(argc, argv);
    MainWindow w;;

    cv::VideoCapture m_cap;;
    int rate = m_cap.get(CV_CAP_PROP_FPS);
    cv::Mat frame;
    cv::VideoWriter videowriter;"test.wmv",CV_FOURCC('W','M','V','2'),30,cv::Size(frame.cols,frame.rows));
    char keycode;
    while ((keycode = cvWaitKey(30))) {
        if (keycode == 27) {
        if (!m_cap.grab()) {
    return a.exec();


  • Lifetime Qt Champion

    HI @_hunter,

    LIBS += /usr/local/lib/

    Please change the linker lines to this,

    LIBS += -L/usr/local/lib -lopencv_shape -lopencv_videoio

    and try again.

    If it does not work, please prove the linker command line from the compile log.


  • @aha_1980 said in opencv error: undefined reference to `cv::VideoCapture::VideoCapture()':

    compile log

    sorry,i do not know the location of compile log.I did what you sugget and here are the new errors:
    :-1: error: main.o: undefined reference to symbol '_ZN2cv6String10deallocateEv'
    /usr/local/lib/ error: error adding symbols: DSO missing from command line
    :-1: error: collect2: error: ld returned 1 exit status

  • @aha_1980 thank you with your help,i solved this error

  • Lifetime Qt Champion


    Glad it worked. So please close this topic as SOLVED. Thanks.

  • @_hunter I'm also getting the same error.. How you solved it. Can you please help me?

  • Lifetime Qt Champion

    @SuganyaSP Did you do what @aha_1980 suggested?

  • @SuganyaSP i am working on ubuntu18 with qt 4.5.2 opencv4
    solved this problem with

    INCLUDEPATH += /usr/local/include/opencv4

    LIBS += $(shell pkg-config opencv --libs)

    LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_shape -lopencv_videoio -lopencv_imgproc

    then make a "rebuid"

Log in to reply