前面用了wxWidgets写好了图形界面,串口接收数据部分,因为其24位位图原因,于是我又选择了OpenCv库,下载完源码后自己编译,因为wxWidgets使用MinGW编的,而两者第后面又要集成到一起,所以OpenCv也要用MinGW编了,使用cMake工具+MinGW。第一次编译失败了,到41%失败,这时候没去看出错信息,又得知用64位MinGW可编,于是乎再次cMake工具+MinGW_x64,编译成功了,但是我忘记了我的wxWidgets使用自带MinGW编的了,哭。。。
后面继续尝试用自带MinGW编译,得到原有错误,这次看了错误,如下:
opencv-3.2.0\modules\highgui\src\window_w32.cpp:50:6: warning: "_WIN32_IE" is not defined [-Wundef]
哦,还有这个编译可以接着上次进度,我后来才知道,之前失败了都傻乎乎的删掉重来。。。还有这个关IE啥事。。。。
对于错误,百度之,fq谷歌之,得到在CodeBlocks\MinGW\include目录下,即gcc编译器的头文件commctrl.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
看这段,嗯,他是不可能被定义的。。。。
外国友人推荐改成如下:(红字部分)
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _WIN32_IE
/* define _WIN32_IE if you really want it */
#if 1
#define _WIN32_IE 0x0500
#endif
#endif
1
#define _WIN32_IE 0x0500
#endif
#endif
我一想,有道理,改之,编译之,结果:
D:\opencv-3.2.0\modules\highgui\src\window_w32.cpp:50:6: warning: "_WIN32_IE" is not defined [-Wundef]
#if (_WIN32_IE < 0x0500)
^
D:\opencv-3.2.0\modules\highgui\src\window_w32.cpp:51:99: note: #pragma message: WARNING: Win32 UI needs to be compiled with _WIN32_IE >= 0x0500 (_WIN32_IE_IE50)
#pragma message("WARNING: Win32 UI needs to be compiled with _WIN32_IE >= 0x0500 (_WIN32_IE_IE50)")
他喵的明明别人说编译通过了
于是去找window_w32.cpp这个,上面警告可知为甚么要改成0x0500
#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
#include <commctrl.h>//注意这行
注意这行
这个。。。。这个顺序怎么会定义呢?
换顺序。。。。。再次编译之.......
D:\opencv-3.2.0\modules\highgui\src\window_w32.cpp: In function 'void cvSetModeWindow_W32(const char*, double)':
D:\opencv-3.2.0\modules\highgui\src\window_w32.cpp:473:47: error: 'MONITOR_DEFAULTTONEAREST' was not declared in this scope
hMonitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
^
D:\opencv-3.2.0\modules\highgui\src\window_w32.cpp:473:71: error: 'MonitorFromRect' was not declared in this scope
hMonitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
^
D:\opencv-3.2.0\modules\highgui\src\window_w32.cpp: In function 'LRESULT MainWindowProc(HWND, UINT, WPARAM, LPARAM)':
D:\opencv-3.2.0\modules\highgui\src\window_w32.cpp:1376:45: error: 'MONITOR_DEFAULTTONEAREST' was not declared in this scope
hMonitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
^
D:\opencv-3.2.0\modules\highgui\src\window_w32.cpp:1376:69: error: 'MonitorFromRect' was not declared in this scope
hMonitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
百度得commctrl包含window编程中的控件API的定义。在用SDK编程时使用控件时使用。于是MONITOR_DEFAULTTONEAREST,MonitorFromRect,就是未定义的东西。
即这一句
hMonitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
由MSDN知此函数头文件定义于
Minimum supported client | Windows 2000 Professional [desktop apps only] |
---|---|
Minimum supported server | Windows 2000 Server [desktop apps only] |
Header | Winuser.h (include Windows.h) |
于是,包含之,再编译。。。。。。。又不行。。。
找到winuser.h有
#if (_WIN32_WINNT >= 0x0500 || _WIN32_WINDOWS >= 0x0410)
WINUSERAPI HMONITOR WINAPI MonitorFromPoint(POINT,DWORD);
WINUSERAPI HMONITOR WINAPI MonitorFromRect(LPCRECT,DWORD);
WINUSERAPI HMONITOR WINAPI MonitorFromWindow(HWND,DWORD);
wtf,百度知if里面的东西是指定windows版本的。。。呵呵
// // _WIN32_WINNT version constants // #define _WIN32_WINNT_NT4 0x0400 // Windows NT 4.0 #define _WIN32_WINNT_WIN2K 0x0500 // Windows 2000 #define _WIN32_WINNT_WINXP 0x0501 // Windows XP #define _WIN32_WINNT_WS03 0x0502 // Windows Server 2003 #define _WIN32_WINNT_WIN6 0x0600 // Windows Vista #define _WIN32_WINNT_VISTA 0x0600 // Windows Vista #define _WIN32_WINNT_WS08 0x0600 // Windows Server 2008 #define _WIN32_WINNT_LONGHORN 0x0600 // Windows Vista #define _WIN32_WINNT_WIN7 0x0601 // Windows 7 #define _WIN32_WINNT_WIN8 0x0602 // Windows 8 #define _WIN32_WINNT_WINBLUE 0x0603 // Windows 8.1 #define _WIN32_WINNT_WINTHRESHOLD 0x0A00 // Windows 10 #define _WIN32_WINNT_WIN10 0x0A00 // Windows 10
就是说MinGW里windows版本可能是0x0400,呵呵
找到然后改掉。。
投降了,换成2.4.13,编译一次通过。。。。强烈怀疑我刚开始下的是develop版本。。