Ask Your Question

undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)' with QT5.8

asked 2018-12-07 04:24:25 -0500

My pltform:

  • Win10 64bit
  • QT58(mingw53)

after installing opencv 3.30, I write code:

#include <iostream>
#include <QDir>
#include <qdebug>
#include "opencv2/opencv.hpp"
using namespace std;
int main()
    qDebug()<< QDir::currentPath();
    cv::Mat image = cv::imread("1.jpg",1);
    std::cout << image.cols << " " << image.rows << std::endl;
    if( == 0){
        cout << "No Image" <<endl;
        cout << "Image" << endl;
   cv::namedWindow("My Image");
   cv::imshow("My Image", image);

   return 0;

I get the error, like this:

release/main.o:main.cpp:(.text.startup+0x170): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
collect2.exe: error: ld returned 1 exit status

I dont know why, but other functions work well,expect imshow(). And I did add the LIBS:

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

LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_highgui330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_calib3d330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_dnn330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_features2d330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_flann330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_imgcodecs330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_imgproc330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_ml330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_objdetect330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_photo330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_shape330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_stitching330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_superres330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_video330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_videoio330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_videostab330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\opencv_ffmpeg330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_core330.dll
edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2018-12-07 05:20:55 -0500

berak gravatar image

updated 2018-12-07 05:21:26 -0500

you have to link libs, not dlls

(*.dll.a in the case of mingw)

also, if you want to use mingw, step #1 would be: build opencv libs from src, using cmake.

other functions work well,

no, your linker just stops complaining after the 1st error.

edit flag offensive delete link more


there is also no need for opencv_ffmpeg330.dll (it will be loaded dynamically, on demand, if nessecary)

berak gravatar imageberak ( 2018-12-07 05:35:09 -0500 )edit

I have built the src with Cmake. *.dll is dynamic link library,*.dll.a is static link library. QT is linked dynamically by default. Especially, imread() have successfully loaded the image, which means some functions do work.

GhostRider gravatar imageGhostRider ( 2018-12-07 08:30:01 -0500 )edit

qt != opencv

(and the dll.a libs are "stub" libs (containing the dlopen/dlsym calls), not static libs (which are plain .a))

berak gravatar imageberak ( 2018-12-07 08:35:18 -0500 )edit

So, I should add LIBS += *.dll.a? Also, what does “stub” libs mean?

GhostRider gravatar imageGhostRider ( 2018-12-07 08:40:24 -0500 )edit

yes, i think, you should use dll.a instead of dll.

and stub means -- those libs only resolve the function pointer from a dll, and pass it on to your program, the actual code is still in the dll.

berak gravatar imageberak ( 2018-12-07 09:11:10 -0500 )edit

uh...I just have try to use *dll.a, but system display "miss *.dll",when I run the test.exe. Instead , it is ok with *.dll

GhostRider gravatar imageGhostRider ( 2018-12-07 09:24:00 -0500 )edit

good ! so it all linked fine now !.

next step: put the folder containing the dll's on the PATH env var, so your exe can find them at runtime

(you might need to restart your cmdline / ide, so it can pick up the changes)

berak gravatar imageberak ( 2018-12-07 09:25:49 -0500 )edit

there is still a problem with imshow()

GhostRider gravatar imageGhostRider ( 2018-12-07 09:27:49 -0500 )edit

IF it built a test.exe, it must be a different problem, now, -- which is ?

berak gravatar imageberak ( 2018-12-07 09:30:48 -0500 )edit

Nope,,same as above.

GhostRider gravatar imageGhostRider ( 2018-12-07 09:32:21 -0500 )edit

answered 2018-12-13 02:53:38 -0500

The solution is to build opencv with debug mode. But I do not know why part of API are not linked in opencv library built with release mode.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-12-07 04:24:25 -0500

Seen: 2,086 times

Last updated: Dec 13 '18