首先设置环境变量,包含mingw的一些路径,minGW路径为E:\CodeBlocks\MinGW
<span style="font-size:14px;">Include :E:\CodeBlocks\MinGW\include;
Lib:E:\CodeBlocks\MinGW\lib;
Path:E:\CodeBlocks\MinGW\bin;E:\CodeBlocks\MinGW\libexec\gcc\mingw32\4.8.1;E:\CodeBlocks\MinGW\mingw32\bin</span>
安装cmake后如果缺少libiconv-2.dll,则将E:\CodeBlocks\MinGW\bin下的libiconv-2.dll拷贝到cmake的安装路径下bin目录中
正常这样generate后会出现一些错误,如下
错误1:
<span style="font-size:14px;">[ 44%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap
_dshow.cpp.obj
D:\opencv\sources\modules\videoio\src\cap_dshow.cpp:122:11: error: base class 's
truct IUnknown' has accessible non-virtual destructor [-Werror=non-virtual-dtor]
interface IEnumPIDMap : public IUnknown
^
D:\opencv\sources\modules\videoio\src\cap_dshow.cpp:141:11: error: base class 's
truct IUnknown' has accessible non-virtual destructor [-Werror=non-virtual-dtor]
interface IMPEG2PIDMap : public IUnknown
^
D:\opencv\sources\modules\videoio\src\cap_dshow.cpp:231:11: error: base class 's
truct IUnknown' has accessible non-virtual destructor [-Werror=non-virtual-dtor]
interface ISampleGrabberCB : public IUnknown
^
D:\opencv\sources\modules\videoio\src\cap_dshow.cpp:245:11: error: base class 's
truct IUnknown' has accessible non-virtual destructor [-Werror=non-virtual-dtor]
interface ISampleGrabber : public IUnknown
^
cc1plus.exe: some warnings being treated as errors
modules\videoio\CMakeFiles\opencv_videoio.dir\build.make:150: recipe for target
'modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_dshow.cpp.obj' failed
mingw32-make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_dsho
w.cpp.obj] Error 1
CMakeFiles\Makefile2:2719: recipe for target 'modules/videoio/CMakeFiles/opencv_
videoio.dir/all' failed
mingw32-make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
makefile:136: recipe for target 'all' failed
mingw32-make: *** [all] Error 2</span>
则需要到sources目录下搜索OpenCVCompilerOptions.cmake,将里面的
add_extra_compiler_option(-Werror=non-virtual-dtor)前面加一个# 即修改为# add_extra_compiler_option(-Werror=non-virtual-dtor)
错误2:
<span style="font-size:14px;">Linking CXX shared library ....\bin\libopencv_core300.dll c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lRunTmChk collect2.exe: error: ld returned 1 exit status modules\core\CMakeFiles\opencv_core.dir\build.make:1257: recipe for target 'bin/libopencv_core300.dll' failed mingw32-make[2]: * [bin/libopencv_core300.dll] Error 1 CMakeFiles\Makefile2:1325: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed mingw32-make[1]:[modules/core/CMakeFiles/opencv_core.dir/all] Error 2 Makefile:136: recipe for target 'all' failed mingw32-make: ** [all] Error 2</span>
则需要在generate之前去掉WITH-IPP选项