【问题标题】:Error while building OpenCV :: MonitorFromRect was not declared in this scope构建 OpenCV 时出错 :: MonitorFromRect 未在此范围内声明
【发布时间】:2014-02-01 21:25:22
【问题描述】:

我试图构建OpenCV version 2.4.8 以将其与CodeBlocksMinGw 一起使用。我按照here 的说明进行操作。但我收到以下错误。我不知道如何解决它。我在网上搜索没有发现任何有用的东西。

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 

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

【问题讨论】:

  • 你运行的是什么opencv版本?在过去的几周里,mingw 支持发生了相当多的变化/战斗,您可能想要更新到最新版本(2.4.8)。
  • @berak 已编辑,我只使用 2.4.8。
  • 看例如here,看看我的意思
  • 感谢@berak,发布后似乎有一些变化。我添加了相关的,现在可以成功构建了。
  • 嘿,酷。只是想让你暗示最新的变化;)

标签: c++ opencv build mingw mingw32


【解决方案1】:

最近提交的所有更改似乎都没有反映在您的签出中。要解决这些问题,请进行以下更改:

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>

这将解决构建错误。

【讨论】:

    【解决方案2】:

    我也遇到过同样的问题,快速浏览了winuser.h 文件后,我知道发生了什么,并在命令行中为CFLAGSCXXFLAGS 添加了必要的宏:

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

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

    【讨论】:

    • 不是答案。也许你应该自己问一个新问题。
    【解决方案3】:

    在构建 OpenCV 3.0.0 RC1 并启用了 mingw32 并启用了 TBB 库时,我遇到了同样的问题。

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

    我通过将 Rajdhar 指示的 _WIN32_WINNT 的定义移动到文件中较早的位置,在 opencv/core 包括之前暂时解决了这个问题:

    #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
    

    【讨论】:

    • 我在 opencv3.2 中遇到了和你一样的问题,你的解决方案正在运行 :) thx
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-20
    • 2019-11-24
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    相关资源
    最近更新 更多