Building OpenCV for Qt
for the past couple of hours I've tried to get OpenCV to work with Qt, but without any luck. I've followed the instructions on this page on the Qt-website to the letter and all goes well until one of the final steps. When I have run CMake the file directory of opencv-build still looks the excact same. It did get significantly bigger though (from 9.27MB to 1.75GB). The problem is that the file structure is in no way what it needs to be and the files needed to link and include in the project file are nowhere to be found. here is a link to a screenshot of the file directory shared with Dropbox. I feel like I am so close, but I really need your help with this one. Thanks in advance!
Hi and welcome to devnet,
Did you call make install ?
Thanks! No i didn't. I called mingw32-make -j 4. I just tried to call make install, but make is not recognized as an internal or external command. My guess is that it needs to be added to path, but I have no idea how.
@MartijnKor Ow wow sorry I feel really stupid now. Just forgot to run the last line of code I realise now. I will try this and give an update. Thanks!
Okay so that worked. Unfortunately I now face another problem. Link to screenshot shared in Dropbox I get a linker error. This is what my libs file directory looks like: another link. Could it have something to do with the .a-extension? I hope anyone has an answer! Thanks!
@MartijnKor You said, you build openCV with mingw32, so you're trying to build your project with the same compiler right?
Also, it says int the docu that extensions and prefixes are not necessary .
However, if I remember correctly, it never worked for me, if I added the extensions -.dll in your case - to the path.
To add to @J-Hilk you don't link to .dll. On Windows the dynamic libraries are not linking target like on Linux. Depending on your compiler you'll have .lib or .a files for that.
Okay thanks! The problem is that my opencv-build directory does not contain any .lib-files.
You have .a files haven't you ?
Well kind of. I have .dll.a files. And I have no idea how to make this work in Qt. The way it is shown in the example does not work for me, no matter what minor changes I try.
What example ?
The example/instructions on the Qt website on how to get opencv to work with Qt for Windows. On the bottom of the page they give an example code to test whether everything has been installed the properly. The instructions are on this page
-Open file "opencv\sources\cmake\OpenCVCompilerOptions.cmake", and comment this line :
-After click in configure, no check : WITH_IPP
-And use mingw32-make , mingw32-make install
Thanks for your help. I deleted my opencv-build directory, commented that line in CMake-file. Did CMake again, with IPP unchecked, ran make and make install again, but no luck. Still the same problem.
Maybe a silly question but, are you also using the Qt MinGW version to build that project ?
@SGaist Yes I am. I installed the mingw included in the Qt online installer and included it in Path. I also select those as the compilers in CMake. Thanks guys for all your help to untill this point. I really appreciate it!
Do you have a static or dynamic build of OpenCV ?
@SGaist That's a good question. According to this YouTube video(I am sorry, but this was quite new for me so I used this as a source of information) at 7:46 it looks like a mix of a static Linux(.a) library and a dynamic Windows(.dll) library, since the files I got after making it have a .dll.a extension.
Anyway, I think I have found the solution for my problem. I will post it right away after this reaction :) Thanks SGaist for all your help!
So after a lot of searching the internet and getting very frustrated I found a solution that seems to work for me so far. I have no idea why this solves the problem and I think it is kind of strange but here is:
On Youtube I found a video where someone explained the exact same steps as described in the original tutorial published by Qt. The problem was the linking. CMake gave me some .dll.a files which I thoughtwas strange.
In this video that person got the excact same files as me (.dll.a). The problem was on how to link these files in the .pro-file.
So here is the solution.
Instead of using this:
LIBS += -LD:\opencv-build\install\x86\mingw\lib \ -lopencv_core320.dll \ -lopencv_highgui320.dll \ -lopencv_imgcodecs320.dll \ -lopencv_imgproc320.dll \ -lopencv_features2d320.dll \ -lopencv_calib3d320.dll
LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_calib3d320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_core320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_features2d320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_flann320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_highgui320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_imgcodecs320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_imgproc320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_ml320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_objdetect320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_photo320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_shape320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_stitching320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_superres320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_video320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_videoio320.dll.a" LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_videostab320.dll.a"
EDIT: This path "C:\opencv-build\install\x86\mingw\lib" also needs to be inserted in Path in System variables I have noticed in order to work.
Using those (longer unfortunately) lines of code, it did work for me. If anyone knows a simpler way of making this work I and presumably other people would appreciate it. Everyone thanks a lot for their help!
Then why not:
LIBS += -LD:/opencv-build/lib \ -lopencv_core320 \ -lopencv_highgui320 \ # etc...