1

I want to link OpenCV in Qt. I do all steps that are here completely and it was successful for every steps. but now I have some errors that is answered here for Linux but I couldn't find the answer for Windows.

Here is a sample of my code:

main.cpp

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

int main(int argc, char *argv[])
{
    cv::Mat input;
    input = cv::imread("‪C:\\Users\\IS UEFI\\Desktop\\pelak_khali.jpg");
    QApplication a(argc, argv);
    QString plate = "";
    MainWindow w(plate);
    w.show();
    std::thread thread(chenges_on_plate, &w);
    int rc = a.exec();
    thread.join(); // wait for the thread to finish
    return rc;
}

.pro file

INCLUDEPATH += D:\QtCommercial\opencv\opencv\build\include

CONFIG(release,debug|release)
{
LIBS += D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_calib3d2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_contrib2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_core2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_features2d2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_flann2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_gpu2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_highgui2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_imgproc2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_legacy2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_ml2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_nonfree2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_objdetect2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_ocl2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_photo2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_stitching2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_superres2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_ts2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_video2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_videostab2411.lib
        }
CONFIG(debug,debug|release)
       {
LIBS += D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_calib3d2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_contrib2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_core2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_features2d2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_flann2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_gpu2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_highgui2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_imgproc2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_legacy2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_ml2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_nonfree2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_objdetect2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_ocl2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_photo2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_stitching2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_superres2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_ts2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_video2411.lib \
        D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_videostab2411.lib
}

I am linking all of the libraries and I use "/" instead of "\" but it doesn't work too.

I do so many ways for fixed it but they couldn't help me unfortunately.

Here is my errors:

error: undefined reference to `cv::imread(std::string const&, int)'
error: undefined reference to `cv::fastFree(void*)'
error: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
error: undefined reference to `cv::Mat::deallocate()'

Thanks before your helps.

Community
  • 1
  • 1
mama23n
  • 135
  • 2
  • 3
  • 10

1 Answers1

1

All of the C++ code that you're using must be compiled with the same compiler at least. Some of the compiler options must also be identical - such as the runtime library to use, whether RTTI is enabled, etc. Otherwise you'll end up with libraries/objects that are slighly binary incompatible and will break in all sorts of confusing manner when you least expect it.

So, Qt, OpenCV and your own code must be compiled with the same compiler. Different MSVC versions are not compatible. Code compiled with MSVC10 might link with MSVC11, but that doesn't mean that it will work correctly. So, never do that.

Practically speaking, the use of binary distributions of C++ projects is not worth it. Compile your own Qt, your own OpenCV, and use them. You'll also be able to debug them with symbol information, so you instantly gain on that front. There's just no other way.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313