Results 1 to 3 of 3

Thread: OpenCV under Windows: undefined reference to `cv::QRCodeDetector::QRCodeDetector()'

  1. #1
    Join Date
    Mar 2016
    Qt products
    Unix/X11 Windows

    Default OpenCV under Windows: undefined reference to `cv::QRCodeDetector::QRCodeDetector()'

    I'm trying to compile my code on Windows 10, with OpenCV 3.4.15 and QT. I work both with Linux and Windows, and usually I haven't particular problems when I compile my app under these different SOs.
    Now I'm placing a simple function (common in a lot of examples you can find in internet) for recognizing and reading a QR code from a webcam. Under Linux, all OK, under Windows...KO. I tried to recompile OpenCV (3.4.15 and 3.4.16), I used dynamically or statically linked library, I used QT 5.13.2, 5.15.2 and 5.15.7, I modified the order of libraries in *.pro file...

    Qt Code:
    1. void scanqr::processQR()
    2. {
    3. Mat qrframe;
    4. if({
    6. * QRCodeDetector decoder = cv::QRCodeDetector();
    8. cv::cvtColor(qrframe,qrframe,COLOR_BGR2RGB);
    10. std::vector<Point> points;
    11. ** std::string data = decoder.detectAndDecode(qrframe, points);
    13. QString scanned_code= QString::fromStdString(data);
    15. ......
    To copy to clipboard, switch view to plain text mode 

    *C:\Users\......scanqr.cpp:87: error: undefined reference to `cv::QRCodeDetector::QRCodeDetector()'
    **C:\Users\......scanqr.cpp:94: error: undefined reference to `cv::QRCodeDetector::detectAndDecode(cv::_InputArr ay const&, cv::_OutputArray const&, cv::_OutputArray const&)'

    As I said, I think it's not a problem about the syntax, because it works under Linux.
    On the other hand, it's difficult for me considering it's caused by OpenCV libraries, as I compiled them in different ways and versions, with the same result. If I comment this function, app is launched and the other OpenCv features (as video acquiring and recording ) work properly.

    In *.pro file I have this reference to OpenCV:

    Qt Code:
    1. # INCLUDEPATH += C:\opencv-3.4.16\BUILD-static\install\include
    2. INCLUDEPATH += C:\opencv-3.4.16\BUILD-dynamic\install\include
    4. # LIBS += -LC:/opencv-3.4.16/BUILD-static/install/x64/mingw/staticlib
    5. LIBS += -LC:/opencv-3.4.16/BUILD-dynamic/install/x64/mingw/staticlib
    7. LIBS += -llibopencv_core3416 -llibopencv_imgproc3416 -llibopencv_features2d3416 -llibopencv_highgui3416 -llibopencv_calib3d3416 -llibopencv_imgcodecs3416 -llibopencv_video3416 -llibopencv_videoio3416 -llibopencv_videostab3416
    To copy to clipboard, switch view to plain text mode 

    Any suggestion?
    Thank a lot!

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 864 Times in 851 Posts
    Qt products

    Default Re: OpenCV under Windows: undefined reference to `cv::QRCodeDetector::QRCodeDetector(

    This definitely sounds like a linker problem. Does the documentation tell you which library the QRCodeDetector class lives? Are all of your rebuilt libraries compiled using the same compiler, compilation settings, bitness, and debug vs. release version?

    For the Microsoft Visual C++ linker, the order of libraries is not relevant; the linker figures out from the exported methods in all of the libraries what needs to be dragged in. MinGW probably uses the GNU linker, where libraries have to be in dependency order. For Visual C++, there is the Dependency Walker tool, which shows the hierarchy of inter-library dependencies. Is there a similar tool in the MinGW / GNU world? I don't know - almost all of my C++ development is on Windows with Microsoft toolchains.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Mar 2016
    Qt products
    Unix/X11 Windows

    Default Re: OpenCV under Windows: undefined reference to `cv::QRCodeDetector::QRCodeDetector(

    You enlightened me!!!
    QRCodeDetector is from Objdetect class, I included the opencv2/objdetect.hpp, but I don't set the libopencv_objdetect341X library in *.pro file!

    Qt Code:
    1. LIBS += -llibopencv_core -llibopencv_highgui -llibopencv_imgproc -lopencv_objdetect -llibopencv_features2d -llibopencv_calib3d -llibopencv_imgcodecs -llibopencv_video -llibopencv_videoio -llibopencv_videostab
    To copy to clipboard, switch view to plain text mode 

    Now it appears like a silly error, but I assure you I checked the libraries many times, spending a lot of time (more than one day), thinking the problem was totally different!

    I'm using MinGW and yes, it uses similar logic to GCC (lib order affects the compiling process).
    I tried Dependency Walker some time ago to check the deployment process, but I'm not very expert about it...

    Thank you very much for your reply, and have a nice evening and weekend.

Similar Threads

  1. Undefined reference to qt-Lib after compiling qt static for amv7 under windows
    By michael_endres in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 23rd January 2014, 18:15
  2. Help with undefined reference in Windows with mingw32
    By qlands in forum Qt Programming
    Replies: 4
    Last Post: 23rd March 2012, 12:41
  3. undefined reference for qt creator in windows
    By morteza in forum Qt Programming
    Replies: 1
    Last Post: 13th October 2011, 20:19
  4. undefined reference
    By deepakswaroop in forum Newbie
    Replies: 1
    Last Post: 2nd March 2011, 07:46
  5. undefined reference
    By digidas in forum Newbie
    Replies: 9
    Last Post: 19th May 2010, 14:04


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.