mingw编译opencv2.4.8

opencv编译过很多次了,这一次我要在win7 64位上使用,所以要编一个64位的库,我的编译器是Qt4.8.0里面的mingw4.4.0 编译opencv2.4.8 还是一个比较高的版本。

相信大家在网上已经看到了很多编译步骤,这里不再多说,但是有一个编译错误你可能会碰得到

[ 26%] Built target pch_Generate_opencv_highgui
[ 26%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_w32.cpp.obj
C:\Program Files (x86)\opencv\sources\modules\highgui\src\window_w32.cpp: In function 'void cvSetModeWindow_W32(const char*, double)':
C:\Program Files (x86)\opencv\sources\modules\highgui\src\window_w32.cpp:477: error: 'MonitorFromRect' was not declared in this scope
C:\Program Files (x86)\opencv\sources\modules\highgui\src\window_w32.cpp: In function 'LRESULT MainWindowProc(HWND__*, UINT, WPARAM, LPARAM)':
C:\Program Files (x86)\opencv\sources\modules\highgui\src\window_w32.cpp:1355: error: 'MonitorFromRect' was not declared in this scope
mingw32-make.exe[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_w32.cpp.obj] Error 1
mingw32-make.exe[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2 
我建议你这样改正

modules/highgui/src/precomp.hpp文件里面删除以下加粗和加黑的内容

 #if defined WIN32 || defined WINCE
     #if !defined _WIN32_WINNT
         #ifdef HAVE_MSMF
            #define _WIN32_WINNT 0x0600 // Windows Vista
         #else
             #define _WIN32_WINNT 0x0500 // Windows 2000
         #endif
    #endif
 
      #include 
然后在 modules/highgui/src/window_w32.cpp文件里面添加一下加粗加黑的内容

 #if defined WIN32 || defined _WIN32

 #define COMPILE_MULTIMON_STUBS // Required for multi-monitor support
 #ifndef _MULTIMON_USE_SECURE_CRT
 #  define _MULTIMON_USE_SECURE_CRT 0 // some MinGW platforms have no strncpy_s
 #endif
 
 #if defined SM_CMONITORS && !defined MONITOR_DEFAULTTONEAREST
 #  define MONITOR_DEFAULTTONULL       0x00000000
 #  define MONITOR_DEFAULTTOPRIMARY    0x00000001
 #  define MONITOR_DEFAULTTONEAREST    0x00000002
 #  define MONITORINFOF_PRIMARY        0x00000001
 #endif
 #ifndef __inout
 #  define __inout
 #endif
 
  #ifdef __GNUC__
  #  pragma GCC diagnostic ignored "-Wmissing-declarations"
  #endif

  #include 
 #include 
  #include 
  #include 
我相信你修改过后就不会报错了。

你可能感兴趣的:(opencv)