OpenCV3.4.1使用CMake和MinGW-w64的编译安装
安装步骤
参考 https://blog.huihut.com/2018/07/31/CompiledOpenCVWithMinGW64/
这篇博文是使用 64 位的 MinGW 编译 OpenCV 生成 64 位的 dll。
因为博主没有 64 位 qmake,所以没勾选 WITH_QT
编译好的 OpenCV(MinGW 版):
Github . huihut/OpenCV-MinGW-Build
软件环境
Windows-10-64bit
MinGW-x64-4.8.1-release-posix-seh-rev5
CMake-3.12.0
OpenCV-3.4.1 | OpenCV-4.0.0-alpha | OpenCV-4.0.0-rc | OpenCV-4.1.0
安装 MinGW-w64 并配置环境变量
下载安装:MinGW-x64-4.8.1-release-posix-seh-rev5
为用户变量 Path 添加 E:\MinGW-w64\x64-4.8.1-release-posix-seh-rev5\mingw64\bin
使环境变量生效
打开命令提示符 CMD,运行 set PATH=C:,更改当前窗口任务的环境变量,关闭这个 CMD。
再次打开另一个 CMD,运行 echo %PATH%,显示最新的环境变量,会发现刚刚添加的 MinGW 环境变量已经生效。
使用 CMake 生成 OpenCV 的 Makefile
打开 cmake-gui,设置源码和生成路径:
Where is the source code: E:/opencv_341/opencv/sources
Where to build the binaries: E:/opencv_341/opencv_mingw64_build
点击 Configure,设置编译器
Specify the generator for this project: MinGW Makefiles
Specify native compilers
Next
Compilers C: E:\MinGW-w64\x64-4.8.1-release-posix-seh-rev5\mingw64\bin\gcc.exe
Compilers C++: E:\MinGW-w64\x64-4.8.1-release-posix-seh-rev5\mingw64\bin\g++.exe
Finish
编译配置:
勾选 WITH_OPENGL
勾选 ENABLE_CXX11
不勾选 WITH_IPP
不勾选 ENABLE_PRECOMPILED_HEADERS
点击 Configure,Generate 生成 Makefile
编译 OpenCV
打开终端进行编译:(-j 是使用 8 个线程进行编译,请根据你的计算机配置合理设置线程数)
E:
cd E:\opencv_341\opencv_mingw64_build
mingw32-make -j 8
mingw32-make install
如果 mingw32-make -j 8 遇到错误,请看下面的 编译 OpenCV 常见错误,否则执行 mingw32-make install,完成安装。
编译中出现的问题
error: ‘::hypot’ has not been declared
solution:
I had this error with building an python file using mingw32 . I opened the file that it says (C:/mingw64/lib/gcc/x86_64-w64-mingw32/6.3.0/include/c++/cmath:1157:11)
and changed that line to
using ::_hypot;
or adding this line just before that :
#define hypot _hypot
and after that the problem was solved !! I know it’s not a basic solution but it is the one that I could find !!
参考: https://stackoverflow.com/questions/42276984/hypot-has-not-been-declared
error: ‘mutex’ in namespace ‘std’ does not name a type
solution:
When I installed MinGW for the first time, I selected under “Threads” the option “win32”, as I thought this was the obvious choice. But to use OpenCV under Windows, you need to select “posix” instead of “win32” threads. This came to my mind while browsing through this thread. In conclusion, if you are not able to compile the source files at this very class/file (detection_based_tracker.cpp.obj), it is very likely due to this.
So, if you are intending of using your own compiled version of OpenCV, I suggest you this:
1.) Download the compiler.
https://sourceforge.net/projects/mingw-w64/
2.) Uninstall your current MinGW compiler.
3.) Reinstall MinGW again.
4.) Understand the option “Threads”, chose “posix”.
I understand, there are different options and ways, this is sole the way, I handled it. And I hope, it might help one or another C++ or OpenCV rookie.
参考:https://github.com/opencv/opencv/issues/10272
Error: invalid register for .seh_savexmm
solution:
known issue. you have to disable the CPU_DISPATCH options for mingw, like:
cmake -DCPU_DISPATCH=
(leave it empty)
also:
-DENABLE_PRECOMPILED_HEADERS=OFF
-DWITH_IPP=OFF
-DWITH_MSMF=OFF
(updating mingw to 8.1.0 was a good idea already !)
参考:https://answers.opencv.org/question/195255/cusersmappdatalocaltempccs5ifdcs20393error-invalid-register-for-seh_savexmm/