Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unable to link opencv library to QT Creator
QtWS25 Last Chance

Unable to link opencv library to QT Creator

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vibelin
    wrote on last edited by
    #1

    Hello everybody,
    I am new to QT, and I am trying to build a desktop application.
    My setup:
    1, QT Creator
    2, QT Version 6.6.0
    3, MingGW 64 bit
    4, opencv 4.5.0
    5, Qmake

    I installed opencv using the windows installer from the official website.
    I set up the library using the Add Library dialog box(I right clicked on the project to see the option). After the library was added, the following code was added to the .pro file of my project.

    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../AI EDA/opencv/build/x64/vc14/lib/' -lopencv_world450
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../AI EDA/opencv/build/x64/vc14/lib/' -lopencv_world450d
    
    INCLUDEPATH += $$PWD/'../AI EDA/opencv/build/include'
    DEPENDPATH += $$PWD/'../AI EDA/opencv/build/include'
    

    I thought I set up everything well, but I am getting the following errors.

    C:\Users\ibrvy\OneDrive\Documents\Inventory_and_Billing\signin.cpp:30: error: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
    :-1: error: debug/signin.o: in function `cv::Mat::~Mat()':
    C:\Users\ibrvy\OneDrive\Documents\AI EDA\opencv\build\include\opencv2\core\mat.inl.hpp:751: error: undefined reference to `cv::fastFree(void*)'
    :-1: error: debug/signin.o: in function `cv::Mat::release()':
    C:\Users\ibrvy\OneDrive\Documents\AI EDA\opencv\build\include\opencv2\core\mat.inl.hpp:863: error: undefined reference to `cv::Mat::deallocate()'
    :-1: error: collect2.exe: error: ld returned 1 exit status
    :-1: error: [Makefile.Debug:99: debug/Inventory_and_Billing.exe] Error 1
    

    This is the code which has the opencv functions, This code is in a constructor of a class, which object is created in the main.cpp. And I am including the headers as well
    #include "opencv2/opencv.hpp"

    using namespace cv;    
    std::string path="C:/Users/ibrvy/OneDrive/Pictures/Video Projects/MISSING VALS.png";
    Mat img=imread(path);
    imshow("Image",img);
    

    I previusly tried with opencv 4.8.0 but I couldn't get it working.
    what am I doing wrong ???

    JonBJ Pl45m4P 2 Replies Last reply
    0
    • V vibelin

      Hello everybody,
      I am new to QT, and I am trying to build a desktop application.
      My setup:
      1, QT Creator
      2, QT Version 6.6.0
      3, MingGW 64 bit
      4, opencv 4.5.0
      5, Qmake

      I installed opencv using the windows installer from the official website.
      I set up the library using the Add Library dialog box(I right clicked on the project to see the option). After the library was added, the following code was added to the .pro file of my project.

      win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../AI EDA/opencv/build/x64/vc14/lib/' -lopencv_world450
      else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../AI EDA/opencv/build/x64/vc14/lib/' -lopencv_world450d
      
      INCLUDEPATH += $$PWD/'../AI EDA/opencv/build/include'
      DEPENDPATH += $$PWD/'../AI EDA/opencv/build/include'
      

      I thought I set up everything well, but I am getting the following errors.

      C:\Users\ibrvy\OneDrive\Documents\Inventory_and_Billing\signin.cpp:30: error: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
      :-1: error: debug/signin.o: in function `cv::Mat::~Mat()':
      C:\Users\ibrvy\OneDrive\Documents\AI EDA\opencv\build\include\opencv2\core\mat.inl.hpp:751: error: undefined reference to `cv::fastFree(void*)'
      :-1: error: debug/signin.o: in function `cv::Mat::release()':
      C:\Users\ibrvy\OneDrive\Documents\AI EDA\opencv\build\include\opencv2\core\mat.inl.hpp:863: error: undefined reference to `cv::Mat::deallocate()'
      :-1: error: collect2.exe: error: ld returned 1 exit status
      :-1: error: [Makefile.Debug:99: debug/Inventory_and_Billing.exe] Error 1
      

      This is the code which has the opencv functions, This code is in a constructor of a class, which object is created in the main.cpp. And I am including the headers as well
      #include "opencv2/opencv.hpp"

      using namespace cv;    
      std::string path="C:/Users/ibrvy/OneDrive/Pictures/Video Projects/MISSING VALS.png";
      Mat img=imread(path);
      imshow("Image",img);
      

      I previusly tried with opencv 4.8.0 but I couldn't get it working.
      what am I doing wrong ???

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @vibelin
      These are linker errors, not compilation ones. I am not an expert, but Google for the error messages like error: undefined reference to cv::fastFree(void*)`. There are several people reporting this and several suggestions. For example, one answer says

      what are you linking ? -lopencv_imgcodecs is needed for imread()

      I'm not sure what you will need now and for MinGW, but I suspect you are still missing some -l... for the undefined references.

      V 1 Reply Last reply
      0
      • V vibelin

        Hello everybody,
        I am new to QT, and I am trying to build a desktop application.
        My setup:
        1, QT Creator
        2, QT Version 6.6.0
        3, MingGW 64 bit
        4, opencv 4.5.0
        5, Qmake

        I installed opencv using the windows installer from the official website.
        I set up the library using the Add Library dialog box(I right clicked on the project to see the option). After the library was added, the following code was added to the .pro file of my project.

        win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../AI EDA/opencv/build/x64/vc14/lib/' -lopencv_world450
        else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../AI EDA/opencv/build/x64/vc14/lib/' -lopencv_world450d
        
        INCLUDEPATH += $$PWD/'../AI EDA/opencv/build/include'
        DEPENDPATH += $$PWD/'../AI EDA/opencv/build/include'
        

        I thought I set up everything well, but I am getting the following errors.

        C:\Users\ibrvy\OneDrive\Documents\Inventory_and_Billing\signin.cpp:30: error: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
        :-1: error: debug/signin.o: in function `cv::Mat::~Mat()':
        C:\Users\ibrvy\OneDrive\Documents\AI EDA\opencv\build\include\opencv2\core\mat.inl.hpp:751: error: undefined reference to `cv::fastFree(void*)'
        :-1: error: debug/signin.o: in function `cv::Mat::release()':
        C:\Users\ibrvy\OneDrive\Documents\AI EDA\opencv\build\include\opencv2\core\mat.inl.hpp:863: error: undefined reference to `cv::Mat::deallocate()'
        :-1: error: collect2.exe: error: ld returned 1 exit status
        :-1: error: [Makefile.Debug:99: debug/Inventory_and_Billing.exe] Error 1
        

        This is the code which has the opencv functions, This code is in a constructor of a class, which object is created in the main.cpp. And I am including the headers as well
        #include "opencv2/opencv.hpp"

        using namespace cv;    
        std::string path="C:/Users/ibrvy/OneDrive/Pictures/Video Projects/MISSING VALS.png";
        Mat img=imread(path);
        imshow("Image",img);
        

        I previusly tried with opencv 4.8.0 but I couldn't get it working.
        what am I doing wrong ???

        Pl45m4P Online
        Pl45m4P Online
        Pl45m4
        wrote on last edited by Pl45m4
        #3

        @vibelin said in Unable to link opencv library to QT Creator:

        EDA/opencv/build/x64/vc14/lib/' -lopencv_world450

        You are using the VC version with MinGW.

        @JonB The opencv_world includes everything, but therefore it's pretty huge and packed with modules you would never use.
        So usually you would link + include only those you are acutally using in your project.
        But it's not wrong to use it :)


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        V 1 Reply Last reply
        1
        • JonBJ JonB

          @vibelin
          These are linker errors, not compilation ones. I am not an expert, but Google for the error messages like error: undefined reference to cv::fastFree(void*)`. There are several people reporting this and several suggestions. For example, one answer says

          what are you linking ? -lopencv_imgcodecs is needed for imread()

          I'm not sure what you will need now and for MinGW, but I suspect you are still missing some -l... for the undefined references.

          V Offline
          V Offline
          vibelin
          wrote on last edited by
          #4

          @JonB
          I already tried most of the solutions available, I even tried the particular solution you have mentioned. This is the error I get when i add 'lopencv_imgcodecs' to the LIBS: statement in my .pro file, Some solutions online suggested using the 'lopencv_imgcodecs450'. I still get the same error

          :-1: error: cannot find -lopencv_imgcodecs450
          
          1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @vibelin said in Unable to link opencv library to QT Creator:

            EDA/opencv/build/x64/vc14/lib/' -lopencv_world450

            You are using the VC version with MinGW.

            @JonB The opencv_world includes everything, but therefore it's pretty huge and packed with modules you would never use.
            So usually you would link + include only those you are acutally using in your project.
            But it's not wrong to use it :)

            V Offline
            V Offline
            vibelin
            wrote on last edited by
            #5

            @Pl45m4
            Should i be using the vc15 instead ?
            What changes should i make ?

            SGaistS 1 Reply Last reply
            0
            • V vibelin

              @Pl45m4
              Should i be using the vc15 instead ?
              What changes should i make ?

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @vibelin hi,

              Either:

              • Use a MinGW build of OpenCV
              • Use Visual Studio (and a VS Qt build)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved