An error occurred while creating OpenCV :: MonitorFromRect was not declared in this area.

I tried to create OpenCV version 2.4.8 to use it with CodeBlocks and MinGw . I followed the instructions here . But I got the following error. I do not know how to solve this. I did not find anything useful in searching the net.

It also does not solve.

I don’t want to mess with OpenCV code, I intend to use OpenCV in my project, and this is the first time I use it.

 [ 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 

I tried to manually include the prototype of the function in the file, but then it comes to linking the error.
will someone tell me what may have gone wrong? How can i solve this?

+6
source share
3 answers

It seems that all the changes from the recent commit are not reflected in your check. To resolve the problems, make the following changes:

In modules/highgui/src/precomp.hpp add the marked line + :

  #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> 

And in modules/highgui/src/window_w32.cpp remove the marked lines - :

  #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> 

This will solve the build error.

+9
source

I had the same problem when creating OpenCV 3.0.0 RC1 with mingw32 support and TBB library.

The fix from Rajdhar is already included in the precomp.h file. However, due to the fact that when creating OpenCV with the TBB library, an additional parameter includes starting the same problem again.

I previously solved the problem by moving the _WIN32_WINNT definition specified by Rajdhar to an earlier point in the file before opencv / core includes:

 #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 
0
source

I had exactly the same problem, and after a quick look at the winuser.h file winuser.h I knew what was happening and added the necessary macros to CFLAGS and CXXFLAGS at the command line:

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

However, the problem is still not resolved. Adding VERBOSE=1 showed that custom CFLAGS and CXXFLAGS did not take effect at all. It was strange, and I think it should have something to do with my environment, although I still could not understand. Anyway, @Rajdhar's answer solved my problem, thanks.

-1
source

All Articles