Question

I was trying to build OpenCV version 2.4.8 to use it with CodeBlocks and MinGw. I followed the instructions from here. But I got the following error. I have no clue how to solve it. I didn't find anything useful by searching in the net.

This is also not solving.

I don't want to mess with the openCV code, I intend to use OpenCV in my project and this is first time I am using 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 error.
will anyone please tell me what may have gone wrong here? How can I solve it?

Was it helpful?

Solution

It seems All the changes from recent commit is not reflected in your check out. 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.

OTHER TIPS

I had the same problem when building OpenCV 3.0.0 RC1 with mingw32 and the TBB library enabled.

The fix from Rajdhar is already included in the precomp.h file. However, due when building OpenCV with the TBB library, the extra includes trigger the same problem again.

I provisionally solved the issue by moving the definition of _WIN32_WINNT indicated by Rajdhar to an earlier point in the file, before the 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

I've had exactly the same problem, and after a quick glance at the file winuser.h, I knew what's going on and added necessary macros to CFLAGS and CXXFLAGS in the command line:

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top