3

I'm trying to create an interface application where I need to use OpenCV to display two videos in one window. I have tried Qt but I have some errors like "unresolved external symbol". I guess that I haven't well linked Qt to OpenCV library. This is my ".pro" file:

#-------------------------------------------------
#
# Project created by QtCreator 2014 - 10 - 31T11:03 : 55
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4) : QT += widgets

TARGET = test_Qt
TEMPLATE = app


SOURCES += main.cpp\
dialog.cpp

HEADERS += dialog.h

FORMS += dialog.ui

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

LIBS += -LD:\\OpenCV231\\mybuild\\lib\\Debug \
    -lopencv_calib3d231d.lib \
    -lopencv_contrib231d.lib \
    -lopencv_core231d.lib \
    -lopencv_features2d231d.lib \
    -lopencv_flann231d.lib \
    -lopencv_gpu231d.lib \
    -lopencv_haartraining_engined.lib \
    -lopencv_highgui231d.lib \
    -lopencv_imgproc231d.lib \
    -lopencv_legacy231d.lib \
    -lopencv_ml231d.lib \
    -lopencv_objdetect231d.lib \
    -lopencv_ts231d.lib \
    -lopencv_video231d.lib

Anyone can help me ? Thanks

Dutchman
  • 41
  • 6
  • 1
    Drop the .lib suffices, so use `-lopencv_food`. The static library should be found automatically. If you try to specify the extension explicitly, it will look for `(lib)opencv_food.lib.{lib/dll}`. By the way, I hate these stupid downvoters who downvote without reasoning. – László Papp Nov 01 '14 at 14:41

2 Answers2

1

Drop the .lib suffices at these places:

-lopencv_calib3d231d.lib \
                    ^^^^

The static library should be found automatically, so just use this schema instead:

-lopencv_calib3d231d \

If you try to specify the extension explicitly, it will look for (lib)opencv_food.lib.{lib/dll}.

You can also specify the whole static library path if you wish to make that is picked up instead of the dynamic library.

László Papp
  • 51,870
  • 39
  • 111
  • 135
  • @Dutchman: have you re-run qmake? If yes, can you show the error message? – László Papp Nov 01 '14 at 15:02
  • No, I didn't use qmake. But I used Cmake to compile OpenCV – Dutchman Nov 01 '14 at 15:19
  • @Dutchman: that must be the problem. Please rerun qmake on your own project in QtCreator. There is a rerun qmake option in the popup menu if you click on your project with the right button of your mouse. – László Papp Nov 01 '14 at 15:27
  • when I run qmake, there are no errors. But when I build, there are always errors like "unresolved external symbol" – Dutchman Nov 01 '14 at 15:37
  • @Dutchman: please paste a simple example that reproduces the problem as well as the exact error output, literally. – László Papp Nov 01 '14 at 15:38
  • dialog.obj:-1: error: LNK2019: unresolved external symbol "public: virtual __thiscall cv::VideoCapture::~VideoCapture(void)" (??1VideoCapture@cv@@UAE@XZ) referenced in function "public: virtual __thiscall Dialog::~Dialog(void)" (??1Dialog@@UAE@XZ) – Dutchman Nov 01 '14 at 15:43
  • dialog.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall cv::VideoCapture::VideoCapture(void)" (??0VideoCapture@cv@@QAE@XZ) referenced in function "public: __thiscall Dialog::Dialog(class QWidget *)" (??0Dialog@@QAE@PAVQWidget@@@Z) – Dutchman Nov 01 '14 at 15:44
  • In the code, I just declared: cv::VideoCapture capWebcam; – Dutchman Nov 01 '14 at 15:46
  • @Dutchman: have you changed `-lopencv_video231d.lib` to `-lopencv_video231d`? Have you checked whether the static library is actually deployed by your opencv installation? If not, you need to build opencv from source, properly. – László Papp Nov 01 '14 at 15:46
  • Yes, I changed as you said. – Dutchman Nov 01 '14 at 15:48
  • Yes, I tried build OpenCV from source by LIBS += -LD:\\OpenCV231\\opencv\\build\\x64\\vc10\\lib \ but it's same – Dutchman Nov 01 '14 at 15:52
  • That is not building from source. Please check whether your opencv installation installs the video library into the location specified. – László Papp Nov 01 '14 at 15:53
  • I used Cmake to compile OpenCV to folder "mybuild" – Dutchman Nov 01 '14 at 15:55
  • Is D:\OpenCV231\mybuild\lib\Debug\opencv_video231d.lib present? – László Papp Nov 01 '14 at 15:56
  • @Dutchman: please check which opencv library brings you the VideoCapture symbol. – László Papp Nov 01 '14 at 16:09
  • Should be in highgui lib!! – Micka Nov 02 '14 at 11:16
  • @Micka: yes, exactly, but he mentioned that, too, so I cannot be sure what is going on. Got a clue? :) – László Papp Nov 02 '14 at 11:22
  • I recreated a new project. And I redo same things. It works. I don't know why. Thanks you very much – Dutchman Nov 22 '14 at 17:16
0

While you can manually edit the .pro file, errors can be avoided by using the "Add Library..." wizard inside Qt Creator.

The steps listed below are found in the Qt5 documentation: [http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html][1] under the "To Add Library" section.

  1. Right click on the project file located in the 'project pane' on the left side of the creator... and select "Add Library..."
  2. Follow the instructions of the wizard

Let me add some specificity from here...

  1. Select "External Library"
  2. For the "Library File" navigate to your opencv_worldXXX.lib file (or opencv_worldXXXd.lib file, you will notice that by specifying only one or the other the wizard has a checkbox which includes the other automatically) [ex. ...\opencv\build\x64\vc12\lib\opncv_world.lib]
  3. For the "Include Folder" navigate to the "include" folder within the build. [ex. ...\opencv\build\include]
  4. Select your operating system, dynamic/static library (whichever is appropriate)
  5. Hit NEXT, CLEAN UP, and RUN!