Still fails for me on gtest-port.cc
x:\Projects\GitHub\googletest\googletest\build>cmake -G "MSYS Makefiles" ..
-- The CXX compiler identification is GNU 4.9.3
-- The C compiler identification is GNU 4.9.3
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found PythonInterp: X:/Python34/python.exe (found version "3.4.1")
-- Configuring done
-- Generating done
-- Build files have been written to: X:/Projects/GitHub/googletest/googletest/buildx:\Projects\GitHub\googletest\googletest\build>make
Scanning dependencies of target gtest
[ 25%] Building CXX object CMakeFiles/gtest.dir/src/gtest-all.cc.obj
In file included from x:/Projects/GitHub/googletest/googletest/src/gtest-all.cc:45:0:
X:/Projects/GitHub/googletest/googletest/src/gtest-port.cc: In static member function 'static void testing::internal::ThreadLocalR
egistryImpl::StartWatcherThreadFor(DWORD)':
X:/Projects/GitHub/googletest/googletest/src/gtest-port.cc:495:21: error: '::OpenThread' has not been declared
HANDLE thread = ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION,
^
make[9]: ** [CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1
make[8]: ** [CMakeFiles/gtest.dir/all] Error 2
make[7]: *** [all] Error 2x:\Projects\GitHub\googletest\googletest\build>cmake --version
cmake version 3.6.0CMake suite maintained and supported by Kitware (kitware.com/cmake).
x:\Projects\GitHub\googletest\googletest\build>g++ --version
g++ (GCC) 4.9.3
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I cant find OpenThread in a source directory. is it another project [OpenThread](https://github.com/openthread)
tried with both -Dgtest_disable_pthreads=ON and -Dgtest_disable_pthreads=OFF. Still requires OpenThread
MinGW should provide OpenThread in windows.h
Found OpenThread in winbase.h but it seems like gtest_port.cc is not getting a declaration.
Also found a few comments like "Do not include windows.h but use forward declarations instead".
I did add
WINBASEAPI HANDLE WINAPI OpenThread(DWORD,BOOL,DWORD);
And removed :: in front of OpenThread and it did work out.
Does it make sense to open a PR so you can take a look?
x:\Projects\GitHub\googletest\googletest\build>cmake -G "MSYS Makefiles" ..
-- The CXX compiler identification is GNU 4.9.3
-- The C compiler identification is GNU 4.9.3
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found PythonInterp: X:/Python34/python.exe (found version "3.4.1")
-- Configuring done
-- Generating done
-- Build files have been written to: X:/Projects/GitHub/googletest/googletest/buildx:\Projects\GitHub\googletest\googletest\build>make
Scanning dependencies of target gtest
[ 25%] Building CXX object CMakeFiles/gtest.dir/src/gtest-all.cc.obj
[ 50%] Linking CXX static library libgtest.a
[ 50%] Built target gtest
Scanning dependencies of target gtest_main
[ 75%] Building CXX object CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj
[100%] Linking CXX static library libgtest_main.a
[100%] Built target gtest_main
I'm not GTest maintainer. Just friendly citizen 馃槃
BTW they include Windows.h here https://github.com/google/googletest/blob/48ee8e98abc950abd8541e15550b18f8f6cfb3a9/googletest/src/gtest-port.cc#L40-L41
Went deeper. apparently OpenThread is not getting included because of this condition:
#if (_WIN32_WINNT >= 0x0500) || (_WIN32_WINDOWS >= 0x0490)
WINBASEAPI HANDLE WINAPI OpenThread(DWORD,BOOL,DWORD);
#endif
So GTest does not define WINVER at all as windows.h requires.
From windef.h
#ifndef WINVER
#define WINVER 0x0400
/*
* If you need Win32 API features newer the Win95 and WinNT then you must
* define WINVER before including windows.h or any other method of including
* the windef.h header.
*/
So I added
#define WINVER 0x0500 // require Win 2000 at least to include OpenThread
Before
# include <windows.h> // NOLINT
Will open a PR for it
I'm using MinGW gcc 4.9.2 and the build with a -DWINVER=0x0500 works for me.
Thanks a bunch! @dsch 's tip helped me to a successful build as well.
Most helpful comment
I'm using MinGW gcc 4.9.2 and the build with a -DWINVER=0x0500 works for me.