Qt and OpenCV

  • I'm attempting to use OpenCV 248 within my Qt Creation application and am hitting a linking snag. In the .pro file I have the following defined:

    @#--------------- specifying opencv libs -----------------

    CV_LIB_PATH = ../../Libs/x64/opencv/build/x64/vc12/staticlib/
    CV_VERSION = 248
    CV_LIBS += opencv_core
    opencv_imgproc \


    CV_DEBUG =
    debug {
    CV_DEBUG += d

    cvpaths =
    cvlibs =
    for(libName, CV_LIBS){
    cvpaths += -L$${CV_LIB_PATH}$${libName}$${CV_VERSION}$${CV_DEBUG}
    cvlibs += -l$${libName}$${CV_VERSION}$${CV_DEBUG}

    INCLUDEPATH += ../../Includes
    LIBS += $${cvpaths} $${cvlibs}@

    -and qmake seems to find everything just fine, no errors. Then in an unassuming object file:

    @#include "autoslicer.h"
    #include "opencv2/core/core.hpp"

    cv::Mat2d a;


    It finds the include just fine. So I know I've got my path's right.
    When I go to build I get a bunch of unresolved's for instantiating that Mat2d. What did I miss? Thanks!

  • Lifetime Qt Champion


    It looks like you have too many \ in your pro file which might be interfering. First thing to do is remove them to be sure that your pro file is clean.

  • Good eye! Now I'm getting complaints about it not being able to open the file... so it would seem my paths WERE wrong. Thanks!

  • So this is strange. Qt can't seem to locate these libraries. I even placed them in the same directory as my .pro, changed the CV_LIB_PATH variable to "". Then I ran qmake with -d (verbose) and checked the following line to be correct:

    @LIBS := -Lopencv_core248d -Lopencv_features2d248d -Lopencv_highgui248d -Lopencv_imgproc248d -lopencv_core248d -lopencv_features2d248d -lopencv_highgui248d -lopencv_imgproc248d@

    These .lib files are as is in the same directory as the .pro, which baffles me as to why I still get a

    @:-1: error: LNK1104: cannot open file 'opencv_core248d.lib'@

  • Lifetime Qt Champion

    Don't you have all opencv lib files in only one folder ?

    @LIBS += -L$$CV_LIB_PATH@

    Should be the only path needed

  • Yeah, I figured out that I was confused with the meaning of the linker options -L and -l. -L points to a directory and then you can use -l for the individual libs, something I didn't totally get. I ended up just expressing the libs without options and used their direct path.

  • Lifetime Qt Champion

    So you go it working ?

Log in to reply

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