OpenCV under Windows: undefined reference to `cv::QRCodeDetector::QRCodeDetector()'
Hi,
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...
Code:
void scanqr::processQR()
{
Mat qrframe;
if(cap.read(qrframe)){
* QRCodeDetector decoder = cv::QRCodeDetector();
cv::cvtColor(qrframe,qrframe,COLOR_BGR2RGB);
std::vector<Point> points;
** std::string data = decoder.detectAndDecode(qrframe, points);
......
*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:
Code:
# INCLUDEPATH += C:\opencv-3.4.16\BUILD-static\install\include
INCLUDEPATH += C:\opencv-3.4.16\BUILD-dynamic\install\include
# LIBS += -LC:/opencv-3.4.16/BUILD-static/install/x64/mingw/staticlib
LIBS += -LC:/opencv-3.4.16/BUILD-dynamic/install/x64/mingw/staticlib
LIBS += -llibopencv_core3416 -llibopencv_imgproc3416 -llibopencv_features2d3416 -llibopencv_highgui3416 -llibopencv_calib3d3416 -llibopencv_imgcodecs3416 -llibopencv_video3416 -llibopencv_videoio3416 -llibopencv_videostab3416
Any suggestion?
Thank a lot!
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.
Re: OpenCV under Windows: undefined reference to `cv::QRCodeDetector::QRCodeDetector(
You enlightened me!!!:D
QRCodeDetector is from Objdetect class, I included the opencv2/objdetect.hpp, but I don't set the libopencv_objdetect341X library in *.pro file!
Code:
LIBS += -llibopencv_core -llibopencv_highgui -llibopencv_imgproc -lopencv_objdetect -llibopencv_features2d -llibopencv_calib3d -llibopencv_imgcodecs -llibopencv_video -llibopencv_videoio -llibopencv_videostab
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.