2014-01-13 56 views
6

我试图构建OpenCVversion 2.4.8以与CodeBlocksMinGw一起使用它。我遵循here的指示。但我得到了以下错误。我不知道如何解决它。我没有发现任何有用的网络搜索。在此范围内未声明构建OpenCV :: MonitorFromRect时出错

This也没有解决。

我不想惹openCV代码,我打算在我的项目中使用OpenCV,这是我第一次使用它。

[ 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 

我试图手动将函数的原型包含在文件中,但后来发现链接错误。
任何人都可以告诉我这里可能出了什么问题吗?我该如何解决它?

+0

你运行的是什么版本的OpenCV?在过去的几周里,在mingw支持方面出现了一些变化/战争,你可能想要更新到最新版本(2.4.8)。 – berak

+0

@berak编辑,我只使用2.4.8。 – Dipto

+0

看起来例如[这里](https://github.com/Itseez/opencv/commit/734bf8babd1b365401bda9c0ab33ee8cbd780254#diff-baec79d9f6cf2a8b605a5d9aad326540),看看我的意思 – berak

回答

9

看来最近提交的所有更改都不会反映在您的结帐中。要解决此问题,进行以下修改:

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> 

这将解决构建错误。

-1

我有完全相同的问题,并在文件winuser.h快速浏览后,我就知道这是怎么回事,并在命令行中添加必要的宏CFLAGSCXXFLAGS

CFLAGS=-D_WIN32_WINNT=0x0500 CXXFLAGS=-D_WIN32_WINNT=0x0500 make

但是,问题仍未解决。添加VERBOSE=1显示自定义CFLAGSCXXFLAGS根本没有生效。这很奇怪,我认为它应该与我的环境有关,但我仍然无法弄清楚。无论如何,@Rajdhar的答案解决了我的问题,谢谢。

+1

它*不是*答案。也许你应该自己提出一个新问题。 – songyuanyao

0

当使用mingw32和TBB库构建OpenCV 3.0.0 RC1时,我遇到了同样的问题。

来自Rajdhar的修复已包含在precomp.h文件中。但是,由于在使用TBB库构建OpenCV时需要额外包含触发同样的问题。

我暂时通过移动通过Rajdhar表示该文件在较早点_WIN32_WINNT的定义解决了问题,以前的OpenCV /核心包括:

#ifndef __HIGHGUI_H_ 
#define __HIGHGUI_H_ 

#include "opencv2/highgui.hpp" 

// MOVED UP 
#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> 
    #undef small 
    #undef min 
    #undef max 
    #undef abs 
#endif 
// END MOVED 

#include "opencv2/core/utility.hpp" 
#include "opencv2/core/private.hpp" 

#include "opencv2/imgcodecs.hpp" 

#include "opencv2/imgproc/imgproc_c.h" 
#include "opencv2/imgcodecs/imgcodecs_c.h" 
#include "opencv2/highgui/highgui_c.h" 

#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
#include <limits.h> 
#include <ctype.h> 
#include <assert.h> 

// MOVED FROM HERE 

#ifdef HAVE_TEGRA_OPTIMIZATION 
#include "opencv2/highgui/highgui_tegra.hpp" 
#endif