opencv3.2.0 Cmake 3.8.0 + tdm-gcc-5.1.0-3 编译问题 highgui _Win32_IE

opencv3.2.0 Cmake 3.8.0 TDM-GCC 5.1.0

Windows 7 遇到如下错误

[ 53%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/videoio/
src/cap_ffmpeg.cpp.obj
D:Resourceopencvsourcesmodulesvideoiosrccap_ffmpeg.cpp:65:42: warning: ty
pe qualifiers ignored on function return type [-Wignored-qualifiers]
static const HMODULE cv_GetCurrentModule()
^
[ 53%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/highgui/
src/window.cpp.obj
[ 53%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/highgui/
src/window_w32.cpp.obj
D:Resourceopencvsourcesmoduleshighguisrcwindow_w32.cpp:51:6: warning: "_W
IN32_IE" is not defined [-Wundef]
#if (_WIN32_IE < 0x0500)
^
D:Resourceopencvsourcesmoduleshighguisrcwindow_w32.cpp:52:99: note: #prag
ma message: WARNING: Win32 UI needs to be compiled with _WIN32_IE >= 0x0500 (_WI
N32_IE_IE50)
#pragma message("WARNING: Win32 UI needs to be compiled with _WIN32_IE >= 0x050
0 (_WIN32_IE_IE50)")

^
D:Resourceopencvsourcesmoduleshighguisrcwindow_w32.cpp: In function 'void
cvSetModeWindow_W32(const char*, double)':
D:Resourceopencvsourcesmoduleshighguisrcwindow_w32.cpp:474:47: error: 'MO
NITOR_DEFAULTTONEAREST' was not declared in this scope
hMonitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
^
D:Resourceopencvsourcesmoduleshighguisrcwindow_w32.cpp:474:71: error: 'Mo
nitorFromRect' was not declared in this scope
hMonitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
^
D:Resourceopencvsourcesmoduleshighguisrcwindow_w32.cpp: In function 'LRES
ULT MainWindowProc(HWND, UINT, WPARAM, LPARAM)':
D:Resourceopencvsourcesmoduleshighguisrcwindow_w32.cpp:1377:45: error: 'M
ONITOR_DEFAULTTONEAREST' was not declared in this scope
hMonitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
^
D:Resourceopencvsourcesmoduleshighguisrcwindow_w32.cpp:1377:69: error: 'M
onitorFromRect' was not declared in this scope
hMonitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
^
D:Resourceopencvsourcesmoduleshighguisrcwindow_w32.cpp: In function 'LRES
ULT HighGUIProc(HWND, UINT, WPARAM, LPARAM)':
D:Resourceopencvsourcesmoduleshighguisrcwindow_w32.cpp:1549:24: warning:
left operand of comma operator has no effect [-Wunused-value]
} while (0,0); // (0,0) instead of (0) to avoid MSVC compiler warni
ng C4127: "conditional expression is constant"
^
modulesworldCMakeFilesopencv_world.diruild.make:4678: recipe for target 'mo
dules/world/CMakeFiles/opencv_world.dir/__/highgui/src/window_w32.cpp.obj' faile
d
mingw32-make[2]: *** [modules/world/CMakeFiles/opencv_world.dir/__/highgui/src/w
indow_w32.cpp.obj] Error 1
CMakeFilesMakefile2:2324: recipe for target 'modules/world/CMakeFiles/opencv_wo
rld.dir/all' failed
mingw32-make[1]: *** [modules/world/CMakeFiles/opencv_world.dir/all] Error 2
Makefile:161: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

在mingw的头文件commctrl.h中,对于上面的变量宏的定义实际上是由_WIN32_IE是否定义来决定的,然而我们找到这个头文件的时候,他的写法是这样:

#include <prsht.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _WIN32_IE
/* define _WIN32_IE if you really want it */
#if 0
#define _WIN32_IE    0x0300
#endif
#endif

  

可更改为

#include <prsht.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _WIN32_IE
/* define _WIN32_IE if you really want it */
#if 1
#define _WIN32_IE    0x0500
#endif
#endif

 或

#if 1
#define _WIN32_IE    0x0300
#endif

 

在opencv 3.2.0 源码中 opencvsourcesmoduleshighguisrcwindow_w32.cpp

#if (_WIN32_IE < 0x0500)
#pragma message("WARNING: Win32 UI needs to be compiled with _WIN32_IE >= 0x0500 (_WIN32_IE_IE50)")
#define _WIN32_IE 0x0500
#endif

另外在windows 7中

C:Program FilesMicrosoft SDKsWindowsv7.1Includesdkddkver.h

有相关内容

// _WIN32_WINNT version constants
//
#define _WIN32_WINNT_NT4                    0x0400
#define _WIN32_WINNT_WIN2K                  0x0500
#define _WIN32_WINNT_WINXP                  0x0501
#define _WIN32_WINNT_WS03                   0x0502
#define _WIN32_WINNT_WIN6                   0x0600
#define _WIN32_WINNT_VISTA                  0x0600
#define _WIN32_WINNT_WS08                   0x0600
#define _WIN32_WINNT_LONGHORN               0x0600
#define _WIN32_WINNT_WIN7                   0x0601

//
// _WIN32_IE_ version constants
//
#define _WIN32_IE_IE20                      0x0200
#define _WIN32_IE_IE30                      0x0300
#define _WIN32_IE_IE302                     0x0302
#define _WIN32_IE_IE40                      0x0400
#define _WIN32_IE_IE401                     0x0401
#define _WIN32_IE_IE50                      0x0500
#define _WIN32_IE_IE501                     0x0501
#define _WIN32_IE_IE55                      0x0550
#define _WIN32_IE_IE60                      0x0600
#define _WIN32_IE_IE60SP1                   0x0601
#define _WIN32_IE_IE60SP2                   0x0603
#define _WIN32_IE_IE70                      0x0700
#define _WIN32_IE_IE80                      0x0800

  

引用自:http://www.cnblogs.com/lhyz/p/4621987.html

    http://code.opencv.org/issues/4087

原文地址:https://www.cnblogs.com/fundou/p/6704638.html