What I want is to build OpenCV for Qt using cmake in Windows, but there were some annoying problems.
The version info:
Qt 5.12.10
cmake 3.20.0
MinGW 7.3.0(Embeded in Qt)
OpenCV 4.5.2 and 3.5.14(I has tried two different versions, but got the similar errors)
successfully in cmake, but I met errors when I run mingw32-make -j 8, the error is
[ 42%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/merge.avx2.cpp.obj
Building CXX object modules/core/CMakeFiles/opencv_core.dir/mean.avx2.cpp.obj
[ 42%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/sum.avx2.cpp.obj
[ 42%] Building RC object modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj
gcc: error: Files\opencv-3.4.14\sources\modules\core\include: No such file or directory
gcc: error: Files\opencv-3.4.14\opencv-build\modules\core: No such file or directory
gcc: error: Files\opencv-3.4.14\sources\3rdparty\zlib: No such file or directory
gcc: error: Files\opencv-3.4.14\opencv-build\3rdparty\zlib: No such file or directory
gcc: error: Files\opencv-3.4.14\sources\3rdparty\include\opencl\1.2: No such file or directory
gcc: error: Files\opencv-3.4.14\opencv-build: No such file or directory
D:\Qt\Qt5.12.10\Tools\mingw730_64\bin\windres.exe: preprocessing failed.
mingw32-make[2]: *** [modules\core\CMakeFiles\opencv_core.dir\build.make:1616: modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj] Error 1
mingw32-make[2]: *** Waiting for unfinished jobs…
[ 42%] Linking CXX static library …\lib\libIlmImf.a
[ 42%] Built target IlmImf
mingw32-make[1]: *** [CMakeFiles\Makefile2:2004: modules/core/CMakeFiles/opencv_core.dir/all] Error 2
mingw32-make: *** [Makefile:165: all] Error 2
PS D:\Program Files\opencv-3.4.14\opencv-build>
It says the cmd in build.make:1616 didn’t run successfully, and I found the file, the content in 1616 line was cd /d "D:\Program Files\opencv-3.4.14\opencv-build\modules\core" && D:\Qt\Qt5.12.10\Tools\mingw730_64\bin\windres.exe -O coff $(RC_DEFINES) $(RC_INCLUDES) $(RC_FLAGS) "D:\Program Files\opencv-3.4.14\opencv-build\modules\core\vs_version.rc" CMakeFiles\opencv_core.dir\vs_version.rc.obj
I has searched a lot about this in Google, and I has tried the following two solutions: 1. uncheck OPENCV_ENABLE_ALLOCATOR_STATA 2. delete $(RC_DEFINES) $(RC_INCLUDES) $(RC_FLAGS) in build.make file, because someone said that they are not important. At first, it’s useful, but after I met very many errors similar to this one in many build.make files in other pathes, I still try this solution, but sometimes it was useless. Finally, the process was terminated completely. Unfortunately, all of them were useless for me.
I don’t know much about cmake and makefile. Maybe that’s why this error has been confusing me for two days. Hope you guys can help me, thank you so so so much.
Yeah, it’s OPENCV_ENABLE_ALLOCATOR_STATS, sorry for my typo.
And I am sure that the version is 4.5.2.
Honestly, I doubt that what I met is not due to the OPENCV_ENABLE_ALLOCATOR_STATS. I noticed that the error message for that should be like below
gcc: error: long: No such file or directory
But for me it’s
gcc: error: Files\opencv-3.4.14\sources\modules\core\include: No such file or directory
gcc: error: Files\opencv-3.4.14\opencv-build\modules\core: No such file or directory
gcc: error: Files\opencv-3.4.14\sources\3rdparty\zlib: No such file or directory
gcc: error: Files\opencv-3.4.14\opencv-build\3rdparty\zlib: No such file or directory
gcc: error: Files\opencv-3.4.14\sources\3rdparty\include\opencl\1.2: No such file or directory
gcc: error: Files\opencv-3.4.14\opencv-build: No such file or directory
It looks like a error about pathes, thouth the mentioned pathes are there indeed.
Following your advice, I build OpenCV using mingw32-make -j 1 again. It’s wired that I met the same error when it finished only 9%. I am more confused…
that’s a terrible place to do this. the blank between “Program” and “Files” breaks it
(it’s looking in “Files\opencv-4.5.2”, which does NOT exist, look at your output, again !)
please try from a different location, copy to a folder without spaces in the path
Great! The space in path is really the reason.
I must note this after.
But there is another problem.
I have not searched it a lot yet. I will post it here. If you know how to solve it, it’s wonderful and I will also try my best to conquer it.
[ 55%] Building CXX object
modules/calib3d/CMakeFiles/opencv_calib3d.dir/src/quadsubpix.cpp.obj
CMakeFiles\opencv_highgui.dir/objects.a(window.cpp.obj):window.cpp:(.text$cvSetWindowProperty+0x27): undefined reference to cvSetPropVsync_W32(char const*, bool)' CMakeFiles\opencv_highgui.dir/objects.a(window.cpp.obj):window.cpp:(.text$cvGetWindowProperty+0x56): undefined reference to cvGetPropVsync_W32(char const*)’
CMakeFiles\opencv_highgui.dir/objects.a(window.cpp.obj):window.cpp:(.text$_ZN2cv17setWindowPropertyERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEid+0x5a): undefined reference to cvSetPropVsync_W32(char const*, bool)' CMakeFiles\opencv_highgui.dir/objects.a(window.cpp.obj):window.cpp:(.text$_ZN2cv17getWindowPropertyERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi+0xc1): undefined reference to cvGetPropVsync_W32(char const*)’
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [modules\highgui\CMakeFiles\opencv_highgui.dir\build.make:222: bin/libopencv_highgui452.dll] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:2666: modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
mingw32-make[1]: *** Waiting for unfinished jobs…
To be honest, I don’t know what I want clearly yet.
I compile OpenCV to meet the requirements of a project I found in GitHub.
The good news is that I has tried the solution in above issue you mentioned, it works.
So I made it, completely!
Thank you so much for taking time to help me.