Integrating OpenCV libraries in QtCreator on Windows



  • Hi Guys,

    I have a certain problem concerning the integration of OpenCV libraries in Qt creator:
    I've downloaded the opencv-249.exe, extracted it and tried to include the libraries by adding to the .pro file the following:

    @ LIBS += "C:\OpenCV\opencv_bin\install\bin\.dll"
    LIBS += "C:\OpenCV\opencv_bin\install\lib\
    .dll*"@

    Unfortunaley I always got Linking errors like " unresolved extern symbol..."

    After that I tried to compile the libraries myself by creating a make-file with cmake adding the "WITH QT" option and compiling it with the mingw32-compiler.

    Unfortunaley I got errors during the compilation.

    After that I tried to compile an older version of OpenCV (I think 2.4.0) and it worked:)
    But if I try to include them in the following test program I always get the error

    bq. :-1: Error: LNK1104: Cannot open file "libopencv_highgui231d.lib"

    @#include "opencv2/opencv.hpp"

    using namespace std;

    int main (int argc, char *argv[]){

        cout << "Hello World!" << endl;
    
        cv::Mat mat;
        mat = cv::imread("BM_Logo.JPG");
        cvNamedWindow("hello");
        cv::imshow("hello",mat);
    
        cvWaitKey(0);
    
        return 0;
    

    }@

    Also I tried to add the libraries by clicking through the menu of qt, and I tried to write each library seperatly
    but still the error is the same.

    I hope there is anybody around here who can help me with this Problem because I am getting crazy around here


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You have to link to the lib files not the dlls. You should also try linking to only the libs your are using.



  • Hi:)

    thank you very much for fast answer. But I don't have .lib files in my own compiled version I only .dll and .dll.a.

    In the built version are some .lib files (although I think they are not for the mingw32-compiler I am using but for vc10)
    I tried to link them but I get the same error

    bq. :-1: Error: LNK1104: Cannot open file “libopencv_highgui231d.lib”


  • Lifetime Qt Champion

    Then let's start at the beginning:
    What compiler do you want to use ? Doesn't the OpenCV pre-built package give you what you need ?



  • I want to use the mingw compiler, there is a folder in the pre-built package called mingw so I suppose this schould work, but it doesnt.

    There are only *dll and *ddl.a files where I get the same errors as above.


  • Lifetime Qt Champion

    You should rather use something like

    @LIBS += -LC:/OpenCV/opencv_bin/install/mingw/whathever
    -lopencv_highgui231d
    -lopencv_core231d
    etc...
    @



  • Yeah thank you very much:) when I added these lines in the .pro file the project gets compiled.

    @LIBS += -LC:/OpenCV/opencv_bin/install/lib/ -llibopencv_core231d
    -llibopencv_highgui231d

    INCLUDEPATH += C:/OpenCV/opencv_bin/install/include
    DEPENDPATH += C:/OpenCV/opencv_bin/install/include
    @

    Unfortunaley after the compiling there is just showing up the console and nothing happends :(


  • Lifetime Qt Champion

    No error message ?



  • no just the "qt_creator_stub.exe"

    but this appears even when I uncomment the whole code


  • Lifetime Qt Champion

    @mat = cv::imread("BM_Logo.JPG");@

    relative path, in that case you should either copy the image in the same folder as your application or give the absolute path to it.



  • No doesnt change anything.

    The strange thing is, even the "Hello World" doesnt appear if I use at least one function of the cv library only when I uncomment these functions the "hello world" appears.

    the output window says:

    bq. return value = -1073741515

    and also the debugger crashes immediatly

    edit:

    I also tried compiling the project with the console, but when I start the .exe it says:

    bq. The programm cannot be started, because the ..highgui249.dll is missing on this computer. Reinstall the programm ...

    When I copy the dlls of opencv in the folder with the executable it says

    bq. The programm cannot be started, because the ..QtCore4.dll is missing on this computer. Reinstall the programm ...


  • Lifetime Qt Champion

    Looks like your OpenCV DLLs can't be found.

    Go the run part of the Project panel, edit the PATH environment variable and add the path to the folder where the OpenCV dlls are located.



  • IT WORKS!!

    Thank you very much:)

    you definitely saved my day:)


  • Lifetime Qt Champion

    You're welcome !

    Since OpenCV is working now, please update the thread title prepending [solved] so other forum users may know solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.