Important: Please read the Qt Code of Conduct -

Is it configuration problem of opencv3.10 with qt 5.5? Showing Error "undefined reference to `cv::imread(cv::String const&, int)"

  • Hello I want to implement sobel operator, so for that i need to read matrix of the input image. I tried to perform with cv::imread() but i am getting the error

    undefined reference to `cv::imread(cv::String const&, int)

    this is my code below


    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        Mat src, dst;
        /// Load an image
        src = cv::imread("C:\\Users\\Prashanth KUMAR\\Pictures\\PhotoGrid_1448276690562.jpg");
          imshow("initial", src);
        delete ui;

    QT       += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = TestSobel
    TEMPLATE = app
    SOURCES += main.cpp\
    HEADERS  += mainwindow.h
    FORMS    += mainwindow.ui

    I read in some posts that it is the problem of including opencv libraries in Qt.

    But my Qt Build environment already has an opencv directory
    here is the screenshot below

    Or is there any other way to link opencv 3.10 with Qt Creator 5.5 in windows?

  • Lifetime Qt Champion


    You need to tell your compiler that you want to link against the OpenCV libraries otherwise it won't know anything about them.

  • @SGaist Thanks for your reply.
    I a new to Qt and OpenCV.
    Can you explain in detail how to do that, or any link which explains that would be helpful?
    I have searched a lot about this but nothing seems to work for me.

  • Lifetime Qt Champion

    What did you try ?
    What error did you get ?
    What compiler are you using ?

  • @SGaist I downloaded and extracted openCV. Later installed Qt. Added the directories
    to the path in Environment variables.

    Later downloaded CMake and installed it and added its path too.
    Created an empty folder opencv-mingw

    In CMake i selected
    the sourcecode Directory as C:\Qt\Tools\mingw492_32\bin
    Buid the binary in C:/opencv-mingw and hit configure button

    Selected MinGW Makefiles from dropdown menu. Then it asked to specify native compilers
    Specified C:/Qt/Tools/mingw491_32/bin/gcc.exe for C
    specified C:/Qt/Tools/mingw491_32/bin/g++.exe for C++
    and hit finish

    Error in configuration process, Project files may be invalid

  • Lifetime Qt Champion

    You are trying to link a Visual Studio build of OpenCV with a MinGW build of Qt. That won't work.

    If already available in your package, use the MinGW version. Otherwise you have to compile OpenCV by hand.

  • @SGaist How to compile it manually?

  • Lifetime Qt Champion

    Take a look at the answer here