Results 1 to 5 of 5

Thread: Qt linking with and OpenCV

  1. #1
    Join Date
    Mar 2014
    Posts
    12
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt linking with 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:

    Qt Code:
    1. #--------------- specifying opencv libs -----------------
    2.  
    3. CV_LIB_PATH = ../../Libs/x64/opencv/build/x64/vc12/staticlib/
    4. CV_VERSION = 248
    5. CV_LIBS += opencv_core \
    6. opencv_features2d \
    7. opencv_highgui \
    8. opencv_imgproc \
    9.  
    10.  
    11. #--------------------------------------------------------
    12.  
    13.  
    14. CV_DEBUG =
    15. debug {
    16. CV_DEBUG += d
    17. }
    18.  
    19. cvpaths =
    20. cvlibs =
    21. for(libName, CV_LIBS){
    22. cvpaths += -L$${CV_LIB_PATH}$${libName}$${CV_VERSION}$${CV_DEBUG}
    23. cvlibs += -l$${libName}$${CV_VERSION}$${CV_DEBUG}
    24. }
    25.  
    26. INCLUDEPATH += ../../Includes \
    27. ../../Includes/opencv/includes \
    28. LIBS += $${cvpaths} $${cvlibs}
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. #include "autoslicer.h"
    2. #include "opencv2/core/core.hpp"
    3.  
    4. Autoslicer::Autoslicer()
    5. {
    6. cv::Mat2d a;
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    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!


    Added after 1 32 minutes:


    So I did notice that I had an extra "\" after my last include path line, fair enough. After checking for other inconsistencies, I ran again, and now Qt is hitting me with a linker 1104, "cannot open output file 'opencv_core248d.lib".

    This puzzled me as the CV_LIB_PATH variable I created seemed correct. So then I put the static libs in with the .pro and changed CV_LIB_PATH to "". (NOTE: CV_LIB_PATH is my own variable I define in the .pro file) Still Qt cannot locate the file (and I would imagine the others). Is there anything glaringly wrong that I did?
    Last edited by Zamaster; 31st March 2014 at 22:55.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt linking with and OpenCV

    You are using a relative path to the libraries. If you are also doing a shadow build this will result in the relative path being interpreted with respect to the build directory and not the source directory. This can lead to libraries not being found. Try an absolute path as an experiment.

    The message "linker 1104, "cannot open output file 'opencv_core248d.lib' " is puzzling since this file is an input not an output. This would seem to indicate that the generated linker command line is broken in some way. I cannot see an obvious problem in your PRO file extract.

  3. #3
    Join Date
    Mar 2014
    Posts
    12
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt linking with and OpenCV

    Good call, I tried an absolute path and I'm getting the same error. Just to see, I turned on verbose for qmake and checked the "LIBS += ..." line. Sure enough, the path to the libraries was correct:

    Qt Code:
    1. LIBS := -LC:/Users/Zamaster/Dropbox/Softwa~1/Mop!/dev/Libs/x64/opencv/build/x64/vc12/staticlib/opencv_core248d -LC:/Users/Zamaster/Dropbox/Softwa~1/Mop!/dev/Libs/x64/opencv/build/x64/vc12/staticlib/opencv_features2d248d -LC:/Users/Zamaster/Dropbox/Softwa~1/Mop!/dev/Libs/x64/opencv/build/x64/vc12/staticlib/opencv_highgui248d -LC:/Users/Zamaster/Dropbox/Softwa~1/Mop!/dev/Libs/x64/opencv/build/x64/vc12/staticlib/opencv_imgproc248d -lopencv_core248d -lopencv_features2d248d -lopencv_highgui248d -lopencv_imgproc248d
    To copy to clipboard, switch view to plain text mode 

    and just for full context the current .pro:

    Qt Code:
    1. QT += core gui opengl
    2.  
    3. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    4.  
    5. TARGET = RegionsBuilder2
    6. TEMPLATE = app
    7.  
    8. #--------------- specifying opencv libs -----------------
    9.  
    10. CV_LIB_PATH = C:/Users/Zamaster/Dropbox/Softwa~1/Mop!/dev/Libs/x64/opencv/build/x64/vc12/staticlib/
    11. CV_VERSION = 248
    12. CV_LIBS += opencv_core \
    13. opencv_features2d \
    14. opencv_highgui \
    15. opencv_imgproc \
    16.  
    17.  
    18. #--------------------------------------------------------
    19.  
    20.  
    21. CV_DEBUG =
    22. debug {
    23. CV_DEBUG += d
    24. }
    25.  
    26. cvpaths =
    27. cvlibs =
    28. for(libName, CV_LIBS){
    29. cvpaths += -L$${CV_LIB_PATH}$${libName}$${CV_VERSION}$${CV_DEBUG}
    30. cvlibs += -l$${libName}$${CV_VERSION}$${CV_DEBUG}
    31. }
    32.  
    33. INCLUDEPATH += ../../Includes \
    34. ../../Includes/opencv/includes
    35.  
    36. LIBS += $${cvpaths} $${cvlibs}
    37.  
    38. SOURCES += main.cpp\
    39. mainwindow.cpp \
    40. myglwidget.cpp \
    41. glminimap.cpp \
    42. glzmap.cpp \
    43. qwidget_slicesheet.cpp \
    44. gldrawsurface.cpp \
    45. spritemachine.cpp \
    46. primitivemachine.cpp \
    47. slicesheet_preview.cpp \
    48. autoslicer.cpp
    49.  
    50. HEADERS += mainwindow.h \
    51. myglwidget.h \
    52. glzmap.h \
    53. glminimap.h \
    54. qwidget_slicesheet.h \
    55. gldrawsurface.h \
    56. spritemachine.h \
    57. primitivemachine.h \
    58. slicesheet_preview.h \
    59. autoslicer.h
    60.  
    61. FORMS += mainwindow.ui \
    62. qwidget_slicesheet.ui
    63.  
    64. RESOURCES += \
    65. res.qrc \
    66. builtin_shaders.qrc
    67.  
    68. OTHER_FILES += \
    69. lineart.vert \
    70. lineart.frag \
    71. sprite.vert \
    72. sprite.frag
    To copy to clipboard, switch view to plain text mode 
    Last edited by Zamaster; 1st April 2014 at 02:28.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt linking with and OpenCV

    My bad. The -L option should specify a directory. If all the library files are in the same directory (I suspect they are) then you should have only one -L and many -l options:
    Qt Code:
    1. LIBS += -LC:/Users/Zamaster/Dropbox/Softwa~1/Mop!/dev/Libs/x64/opencv/build/x64/vc12/staticlib
    2. LIBS += -lopencv_core248d -lopencv_features2d248d -lopencv_highgui248d -lopencv_imgproc248d
    To copy to clipboard, switch view to plain text mode 
    You would need to adjust (simplify) your PRO file accordingly .

    The alternative is to specify the full path and name of the libraries without any -L or -l options:
    Qt Code:
    1. LIBS += C:/Users/Zamaster/Dropbox/Softwa~1/Mop!/dev/Libs/x64/opencv/build/x64/vc12/staticlib/opencv_core248d.lib
    2. LIBS += C:/Users/Zamaster/Dropbox/Softwa~1/Mop!/dev/Libs/x64/opencv/build/x64/vc12/staticlib/opencv_features2d248d.lib
    3. LIBS += C:/Users/Zamaster/Dropbox/Softwa~1/Mop!/dev/Libs/x64/opencv/build/x64/vc12/staticlib/opencv_highgui248d.lib
    4. LIBS += C:/Users/Zamaster/Dropbox/Softwa~1/Mop!/dev/Libs/x64/opencv/build/x64/vc12/staticlib/opencv_imgproc248d.lib
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Mar 2014
    Posts
    12
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt linking with and OpenCV

    Perfect! I clearly was strugglin' with the meaning of the linker options. This fixed my problem. Thanks.

Similar Threads

  1. Linking openCV with qt
    By harvey_slash in forum Newbie
    Replies: 4
    Last Post: 24th January 2014, 19:57
  2. Static Linking Qt with openCV
    By harvey_slash in forum Newbie
    Replies: 4
    Last Post: 17th December 2013, 08:36
  3. linking with opencv
    By karuna in forum General Programming
    Replies: 2
    Last Post: 27th February 2013, 11:24
  4. [OpenCV] Linking problem
    By danioto in forum Newbie
    Replies: 3
    Last Post: 1st November 2012, 01:33
  5. Linking Error Qt OpenCV
    By Songi in forum Installation and Deployment
    Replies: 4
    Last Post: 28th August 2011, 04:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.