Win10下Qt+OpenCV+Cmake編譯錯誤

小雨絲兒絲兒的發表於2020-12-09

Win10下Qt+OpenCV+Cmake編譯錯誤

 

工具:

QT5.14.2

cmake-3.19.1-win64-x64

opencv4.3.0

mingw-w64-install

 

安裝完Opencv、Qt和Cmake之後在cmd下通過mingw32-make編譯,結果出現錯誤,錯誤提示如下:

 

錯誤(一):

gcc: error: long: No such file or directory

C:\Strawberry\c\bin\windres.exe: preprocessing failed.

mingw32-make[2]: *** [modules\core\CMakeFiles\opencv_core.dir\build.make:1494: modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj] Error 1

mingw32-make[1]: *** [CMakeFiles\Makefile2:1909: modules/core/CMakeFiles/opencv_core.dir/all] Error 2

mingw32-make: *** [Makefile:181: all] Error 2

 

原因:the windres.exe mingw uses cannot handle/escape “long long” given as a cmdline arg

解決方法:在cmake裡面找到OPENCV_ENABLE_ALLOCATOR_STATS或者在search裡面搜尋,然後把後面的勾選去掉,接著Configure和Generate後,接著在cmd視窗中mingw32-make即可繼續編譯。

 

 

錯誤(二):

D:/Qt6/Tools/mingw730_64/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `CMakeFiles\opencv_core.dir/objects.a(vs_version.rc.obj)' is incompatible with i386:x86-64 output

collect2.exe: error: ld returned 1 exit status

mingw32-make[2]: *** [modules\core\CMakeFiles\opencv_core.dir\build.make:1708: bin/libopencv_core430.dll] Error 1

mingw32-make[1]: *** [CMakeFiles\Makefile2:1909: modules/core/CMakeFiles/opencv_core.dir/all] Error 2

mingw32-make: *** [Makefile:181: all] Error 2

 

原因:相容問題

解決方法:http://mingw-w64.org/doku.php/download下載安裝mingw-w64-install,成功後接著Configure和Generate後,在cmd視窗中mingw32-make即可繼續編譯

 

錯誤(三):

[ 33%] Linking CXX shared library ..\..\bin\libopencv_core430.dll

D:/Qt6/Tools/mingw730_64/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `CMakeFiles\opencv_core.dir/objects.a(vs_version.rc.obj)' is incompatible with i386:x86-64 output

collect2.exe: error: ld returned 1 exit status

mingw32-make[2]: *** [modules\core\CMakeFiles\opencv_core.dir\build.make:1708: bin/libopencv_core430.dll] Error 1

mingw32-make[1]: *** [CMakeFiles\Makefile2:1909: modules/core/CMakeFiles/opencv_core.dir/all] Error 2

mingw32-make: *** [Makefile:181: all] Error 2

 

解決方法:在cmake gui中新增條目OPENCV_VS_VERSIONINFO_SKIP = 1,再重新Configure,Generate後,在cmd視窗中mingw32-make即可繼續編譯

 

 

 

 

 

 

 

 

 

 

相關文章