Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv installation error while mingw32-make on windows

opencv installation using mingw32-make command in windows 10 platform, then likely end up in getting the below error.

Windows version : 10 OpenCv:3.2.0

Please suggest me in installing.

D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In constructor 'testing::internal::Mutex::Mutex()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8829:45: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in initialization
       critical_section_(new CRITICAL_SECTION) {
                                             ^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8830:48: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
   ::InitializeCriticalSection(critical_section_);
                                                ^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In destructor 'testing::internal::Mutex::~Mutex()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8840:46: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'PCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void DeleteCriticalSection(PCRITICAL_SECTION)'
     ::DeleteCriticalSection(critical_section_);
                                              ^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Lock()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8848:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void EnterCriticalSection(LPCRITICAL_SECTION)'
   ::EnterCriticalSection(critical_section_);
                                           ^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Unlock()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8858:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void LeaveCriticalSection(LPCRITICAL_SECTION)'
   ::LeaveCriticalSection(critical_section_);
                                           ^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::ThreadSafeLazyInit()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8879:27: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in assignment
         critical_section_ = new CRITICAL_SECTION;
                           ^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8880:54: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
         ::InitializeCriticalSection(critical_section_);
                                                      ^
modules\ts\CMakeFiles\opencv_ts.dir\build.make:237: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj' failed
mingw32-make[2]: *** [modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj] Error 1
CMakeFiles\Makefile2:5379: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/all' failed
mingw32-make[1]: *** [modules/ts/CMakeFiles/opencv_ts.dir/all] Error 2
Makefile:159: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
like image 337
Amarnath R Avatar asked Feb 05 '23 05:02

Amarnath R


1 Answers

I also faced the same problem while trying to build OpenCV 3.2.0 using mingw32 on Windows10. I searched a bit to find a fix on Github for similar problem. It said the problem was:

MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two separate (equivalent) structs, instead of using typedef

So, you have to add another typedef GTEST_CRITICAL_SECTION for _CRITICAL_SECTION and _RTL_CRITICAL_SECTION and use this typedef for either case.

Here is what to do :

Edit "ts_gtest.h" which is inside "opencv\sources\modules\ts\include\opencv2\ts\"

  1. Replace this line (probably line 723)


    // 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;


with



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


  1. Replace this line (probably on line 3060 before your edit - line number would have changed as you modified first part)


    _RTL_CRITICAL_SECTION* critical_section_;


with



    GTEST_CRITICAL_SECTION* critical_section_;


These two changes should fix your above error.

like image 89
msk Avatar answered Mar 03 '23 18:03

msk