Eclipse CDT/CodeBlocks & MinGW & OpenCV 2.x 配置

一、Eclipse CDT配置见blog.csdn.net/caroline_wendy,CodeBlocks配置见opencv.org.cn(OpenCV的编译步骤同Eclipse)

以下补充是本人在实践中碰到问题的解决方法:
(1)使用mingw4.7时编译,如果运行时碰到类似"丢失libgcc_s_dw2-1.dll"、“无法动态加载libstdc++-6”等,解决方法:在链接器选项里加-lstdc++ -static两个选项了 ,或者将mingw的路径(如mingw/bin)加入环境变量

(2)如果运行时碰到有关OpenCV库问题,建议将通过mingw编译的opencv库的路径(如opencv\mingw\bin)加入环境变量

(3)用CMake,mingw编译opencv 2.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 
解决方法(该方法来自 stackoverflow.com),按照如下方法修改两个源文件后再次编译通过。

在 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 <windows.h>

在 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 <commctrl.h>
 -#include <winuser.h>
  #include <stdlib.h>
  #include <string.h>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值