after reboot undefined reference to `cv::imread(std::string const&, int)'

asked 2014-05-24 23:28:03 -0600

glicanear gravatar image

updated 2014-05-25 01:37:44 -0600

I have Qt 5.3.0 for Android (Windows 32-bit, 813 MB) on Windows x64

Compiled opencv with cmake - both release and debug versions

PATH

c:\Dev\opencv\debug\install\x64\mingw\bin\;
c:\Dev\opencv\release\install\x64\mingw\bin\;
C:\Qt\Qt5.3.0\5.3\mingw482_32\bin;
C:\Qt\Qt5.3.0\Tools\mingw482_32\bin\;
C:\Dev\CMake\bin;

.pro project file has only these lines added:

INCLUDEPATH += C:\\Dev\\opencv\\release\\install\\include
LIBS += -LC:\\Dev\\opencv\\release\\install\\x64\\mingw\\bin\\*.*

main.cpp simple test example

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main() {
        // read an image
        cv::Mat image= cv::imread("img.jpg");
        // create image window named "My Image"
        cv::namedWindow("My Image");
        // show the image on window
        cv::imshow("My Image", image);
        // wait key for 5000 ms
        cv::waitKey(5000);
        return 1;
}

This example was running. Now when I try to do the same after reboot - getting these results: C:\workspace\untitled7\main.cpp:9: error: undefined reference to `cv::imread(std::string const&, int)'

No clue at all what should be done. Apparently it doesn't link, but why it did in first run? Exactly the same result I'm getting in linux environment. Why?

...

SOLUTION:

I ended up with just adding libraries in this manner(different project, but tested and it worked for this example):

win32:LIBS += c:\Dev\opencv\release\install\x64\mingw\lib\libopencv_core249.dll.a 
win32:LIBS += c:\Dev\opencv\release\install\x64\mingw\lib\libopencv_highgui249.dll.a 
win32:LIBS += c:\Dev\opencv\release\install\x64\mingw\lib\libopencv_imgproc249.dll.a 
win32:LIBS += c:\Dev\opencv\release\install\x64\mingw\lib\libopencv_features2d249.dll.a 
win32:LIBS += c:\Dev\opencv\release\install\x64\mingw\lib\libopencv_calib3d249.dll.a

No idea why it was working with initial settings. It was fresh System with new Qt install and compiled opencv. Since there has been many similar posts and none of them have explained, that libraries can be linked to a .dll.a files, let's hope that it will help others, who will have similar Qt setup problems.

Also I'm curious why opencv is not shipping with prebuilt Qt libraries - it is not rare C/C++ tool and probably by now as widespread as Visual Studio. I was using Visual Studio for years and moved(run away) to Qt, because it offered the same - GUI without the need to delve into configuration of command lines and also possibility to use it on multiple operational systems. Visual Studio is just bound with one - MS and it is conflicting idea to call opencv open if it is so bound to MS.

I think, I've found answer. It was really lib directory, not bin.

PS Haha, I can' t close my own question or just don't know how to set it as answered.

edit retag flag offensive close merge delete

Comments

1

just curious: should that code run on desktop or on android ?

undefined reference. that means, it could not find a lib(or .a).

LIBS += -LC:\Dev\opencv\release\install\x64\mingw\bin\. <-- \lib\. ?

berak gravatar imageberak ( 2014-05-24 23:45:54 -0600 )edit

For android you have to link against opencv android sdk My configuration for LIBS was: c:\Dev\OpenCV-2.4.9-android-sdk\sdk\native\libs\armeabi-v7a*.* and include was c:\Dev\OpenCV-2.4.9-android-sdk\sdk\native\jni\include\

Actually I have the same problem there - it compiled and installed, but now can't to do again. I mean - it installed with some errors, but now I can' t even get past that - it doesn't compile and give same error. So, same problem.

Well, under bin folder there are .dll files... anyway - there are conflicting and outdated tutorials out there and tried both versions. It doesn't compile right now at all, but it compiled in first place with bin - I think that I stick to bin folder, because before clean system reinstallation I switched to lib and it didn' t worked.

glicanear gravatar imageglicanear ( 2014-05-24 23:55:52 -0600 )edit

I ended up with just adding these libraries:

win32:LIBS += c:\Dev\opencv\release\install\x64\mingw\lib\libopencv_core249.dll.a win32:LIBS += c:\Dev\opencv\release\install\x64\mingw\lib\libopencv_highgui249.dll.a win32:LIBS += c:\Dev\opencv\release\install\x64\mingw\lib\libopencv_imgproc249.dll.a win32:LIBS += c:\Dev\opencv\release\install\x64\mingw\lib\libopencv_features2d249.dll.a win32:LIBS += c:\Dev\opencv\release\install\x64\mingw\lib\libopencv_calib3d249.dll.a

glicanear gravatar imageglicanear ( 2014-05-25 01:09:06 -0600 )edit

thanks for reporting back. will be helpful for others.

berak gravatar imageberak ( 2014-05-25 03:56:51 -0600 )edit