Cant' build OpenCV 3.2.0 (Mingw32)

922 views Asked by At

I know... Another one of this... But no one else's error is the same as mine and I've been trying to build opencv with mingw32 for days now.

When building OpenCV with mingw the command mingw32-make fails at some point trying to compile sources\modules\ts\src\ts_gtest.cpp with error pic bellow:

mingw32-make compile error

I've tried following several tutorials, but none work cleanly and this is the best I could get stuff to work.

What I did:

  • Installed Mingw and added C:\Mingw\bin\ to PATH environment variable.
  • Installed CMake and added it too to PATH.
  • Extracted OpenCV to C:\ and created forlder C:\opencv\mingwBuild\
  • In CMake-GUI I define source folder as C:\opencv\sources\ and build folder as C:\opencv\mingwBuild\.
  • Hit Configure and select Mingw Makefiles, with 'Use default native compilers' (have also specified compilers explicitly and the result is the same.).
  • Hit Generate, which creates the Makefile.
  • I open C:\Mingw\msys\1.0\msys.bat to have a console with all variables loaded (have also tried directly from a simple cmd.exe, given that PATH is set for mingw, but I get the same error in compilation). Navigate to C:\opencv\mingwBuild\ and run mingw32-make.

And that's where the error shows up after a while. Any ideas?

2

There are 2 answers

0
A. Vieira On

Turns ou gTest was not compiling in Mingw for some reason. As I don't intend to test my code (for now) I removed opencv_ts from instalation (by deselecting it in Cmake, after configuring and before generating).

Someone mentions, in the first link @Dan Masek refers, that GTest has this issue with type conversion under mingw. They say that you can edit ts_gtest.cpp to apply the correct conversion, according to error message. That may be a solution if you need this module.

Another comment in @Dan Masek's second link mentions that gcc's version 5 surpasses the issue, which version 4 has. So, getting a hold of such distro may also be a solution.

0
Jo Korppi On

For me it seems to be fixed by applying this fix: https://github.com/msk-repo01/opencv/commit/9a1835ce6676836ce278d723da4ff55a8f900ff1

(Also see: https://github.com/opencv/opencv/issues/8105)

The fix basically replaces the "_RTL_CRITICAL_SECTION" by "_CRITICAL_SECTION" for MingW compilers in modules/ts/include/opencv2/ts/ts_gtest.h in the following way: The lines

// assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
struct _RTL_CRITICAL_SECTION;

(around line 723 in OpenCV 3.2.0 release from Dec. 2016) are replaced by

# if GTEST_OS_WINDOWS_MINGW
   // MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two
   // separate (equivalent) structs, instead of using typedef
   typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
# else
   // assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
   // This assumption is verified by
   // WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
   typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
# endif

and

_RTL_CRITICAL_SECTION* critical_section_;

is replaced by

GTEST_CRITICAL_SECTION* critical_section_;