opencv3.2.0 + Cmake 3.8.0 + tdm-gcc-5.1.0-3 编译错误问题 ts_gtest

opencv3.2.0  Cmake 3.8.0 TDM-GCC 5.1.0 tdm32-1

Windows 7 遇到如下错误

[ 63%] Building CXX object modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.
obj
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp: In constructor 'testing:
:internal::Mutex::Mutex()':
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp:8829:45: error: cannot co
nvert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' i
n initialization
critical_section_(new CRITICAL_SECTION) {
^
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp:8830:48: error: cannot co
nvert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}'
for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
::InitializeCriticalSection(critical_section_);
^
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp: In destructor 'testing::
internal::Mutex::~Mutex()':
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp:8840:46: error: cannot co
nvert '_RTL_CRITICAL_SECTION*' to 'PCRITICAL_SECTION {aka _CRITICAL_SECTION*}' f
or argument '1' to 'void DeleteCriticalSection(PCRITICAL_SECTION)'
::DeleteCriticalSection(critical_section_);
^
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp: In member function 'void
testing::internal::Mutex::Lock()':
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp:8848:43: error: cannot co
nvert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}'
for argument '1' to 'void EnterCriticalSection(LPCRITICAL_SECTION)'
::EnterCriticalSection(critical_section_);
^
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp: In member function 'void
testing::internal::Mutex::Unlock()':
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp:8858:43: error: cannot co
nvert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}'
for argument '1' to 'void LeaveCriticalSection(LPCRITICAL_SECTION)'
::LeaveCriticalSection(critical_section_);
^
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp: In member function 'void
testing::internal::Mutex::ThreadSafeLazyInit()':
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp:8879:27: error: cannot co
nvert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' i
n assignment
critical_section_ = new CRITICAL_SECTION;
^
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp:8880:54: error: cannot co
nvert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}'
for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
::InitializeCriticalSection(critical_section_);
^
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp: In static member functio
n 'static void testing::internal::ThreadLocalRegistryImpl::StartWatcherThreadFor
(DWORD)':
D:Resourceopencvsourcesmodules ssrc s_gtest.cpp:9082:21: error: '::OpenTh
read' has not been declared
HANDLE thread = ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION,
^
modules sCMakeFilesopencv_ts.diruild.make:237: recipe for target 'modules/t
s/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
CMakeFilesMakefile2:2455: recipe for target 'modules/ts/CMakeFiles/opencv_ts.di
r/all' failed
mingw32-make[1]: *** [modules/ts/CMakeFiles/opencv_ts.dir/all] Error 2
Makefile:161: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

根源

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

方案

Edit "ts_gtest.h" which is inside "opencvsourcesmodules sincludeopencv2 s"

  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.

引用自:http://stackoverflow.com/questions/41930349/opencv-installation-error-while-mingw32-make-on-windows

原文地址:https://www.cnblogs.com/fundou/p/6703093.html