title: glog doesn't compile on Windows with MinGW
body: <p>It seems that glog doesn't compile on Windows with MinGW. Cmake configuration and generation is OK, but when I start the mingw32-make.exe -j10 command, I get a lot of errors related with ambiguity declarations.</p>
  <p>This is the complete cmake configure and generate command output:</p>
  <pre><code>D:\INSTALL\Development\lib\ceres-mingw\glog\build&gt;&quot;D:\Program Files\CMake\bin\cmake.exe&quot; -G &quot;MinGW Makefiles&quot; -Dgflags_DIR=&quot;D:\INSTALL\Development\lib\ceres-mingw\gflags\build&quot; ..
  -- The C compiler identification is GNU 9.2.0
  -- The CXX compiler identification is GNU 9.2.0
  -- Check for working C compiler: D:/MinGW/bin/gcc.exe
  -- Check for working C compiler: D:/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
  -- Check for working CXX compiler: D:/MinGW/bin/g++.exe
  -- Check for working CXX compiler: D:/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
  -- Looking for gflags namespace
  -- Looking for gflags namespace - gflags
  -- Looking for pthread.h
  -- Looking for pthread.h - found
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
  -- Looking for pthread_create in pthreads
  -- Looking for pthread_create in pthreads - not found
  -- Looking for pthread_create in pthread
  -- Looking for pthread_create in pthread - found
  -- Found Threads: TRUE
  -- Could NOT find Unwind (missing: Unwind_INCLUDE_DIR Unwind_LIBRARY Unwind_PLATFORM_LIBRARY)
  -- Looking for dlfcn.h
  -- Looking for dlfcn.h - found
  -- Looking for execinfo.h
  -- Looking for execinfo.h - not found
  -- Looking for glob.h
  -- Looking for glob.h - found
  -- Looking for inttypes.h
  -- Looking for inttypes.h - found
  -- Looking for memory.h
  -- Looking for memory.h - found
  -- Looking for pwd.h
  -- Looking for pwd.h - not found
  -- Looking for stdint.h
  -- Looking for stdint.h - found
  -- Looking for stdlib.h
  -- Looking for stdlib.h - found
  -- Looking for string.h
  -- Looking for string.h - found
  -- Looking for strings.h
  -- Looking for strings.h - found
  -- Looking for sys/stat.h
  -- Looking for sys/stat.h - found
  -- Looking for sys/syscall.h
  -- Looking for sys/syscall.h - not found
  -- Looking for sys/time.h
  -- Looking for sys/time.h - found
  -- Looking for sys/types.h
  -- Looking for sys/types.h - found
  -- Looking for sys/utsname.h
  -- Looking for sys/utsname.h - not found
  -- Looking for sys/wait.h
  -- Looking for sys/wait.h - not found
  -- Looking for syscall.h
  -- Looking for syscall.h - not found
  -- Looking for syslog.h
  -- Looking for syslog.h - not found
  -- Looking for ucontext.h
  -- Looking for ucontext.h - not found
  -- Looking for unistd.h
  -- Looking for unistd.h - found
  -- Looking for C++ include ext/hash_map
  -- Looking for C++ include ext/hash_map - found
  -- Looking for C++ include ext/hash_set
  -- Looking for C++ include ext/hash_set - found
  -- Looking for C++ include ext/slist
  -- Looking for C++ include ext/slist - found
  -- Looking for C++ include tr1/unordered_map
  -- Looking for C++ include tr1/unordered_map - found
  -- Looking for C++ include tr1/unordered_set
  -- Looking for C++ include tr1/unordered_set - found
  -- Looking for C++ include unordered_map
  -- Looking for C++ include unordered_map - found
  -- Looking for C++ include unordered_set
  -- Looking for C++ include unordered_set - found
  -- Looking for stddef.h
  -- Looking for stddef.h - found
  -- Check size of unsigned __int16
  -- Check size of unsigned __int16 - done
  -- Check size of u_int16_t
  -- Check size of u_int16_t - failed
  -- Check size of uint16_t
  -- Check size of uint16_t - done
  -- Looking for dladdr
  -- Looking for dladdr - not found
  -- Looking for fcntl
  -- Looking for fcntl - not found
  -- Looking for pread
  -- Looking for pread - not found
  -- Looking for pwrite
  -- Looking for pwrite - not found
  -- Looking for sigaction
  -- Looking for sigaction - not found
  -- Looking for sigaltstack
  -- Looking for sigaltstack - not found
  -- Performing Test HAVE_NO_DEPRECATED
  -- Performing Test HAVE_NO_DEPRECATED - Success
  -- Performing Test HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS
  -- Performing Test HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS - Failed
  -- Looking for snprintf
  -- Looking for snprintf - found
  -- Looking for UnDecorateSymbolName in dbghelp
  -- Looking for UnDecorateSymbolName in dbghelp - not found
  -- Performing Test HAVE___ATTRIBUTE__
  -- Performing Test HAVE___ATTRIBUTE__ - Success
  -- Performing Test HAVE___ATTRIBUTE__VISIBILITY_DEFAULT
  -- Performing Test HAVE___ATTRIBUTE__VISIBILITY_DEFAULT - Success
  -- Performing Test HAVE___ATTRIBUTE__VISIBILITY_HIDDEN
  -- Performing Test HAVE___ATTRIBUTE__VISIBILITY_HIDDEN - Success
  -- Performing Test HAVE___BUILTIN_EXPECT
  -- Performing Test HAVE___BUILTIN_EXPECT - Success
  -- Performing Test HAVE___SYNC_VAL_COMPARE_AND_SWAP
  -- Performing Test HAVE___SYNC_VAL_COMPARE_AND_SWAP - Success
  -- Performing Test HAVE_RWLOCK
  -- Performing Test HAVE_RWLOCK - Failed
  -- Performing Test HAVE___DECLSPEC
  -- Performing Test HAVE___DECLSPEC - Success
  -- Performing Test STL_NO_NAMESPACE
  -- Performing Test STL_NO_NAMESPACE - Failed
  -- Performing Test STL_STD_NAMESPACE
  -- Performing Test STL_STD_NAMESPACE - Success
  -- Performing Test HAVE_USING_OPERATOR
  -- Performing Test HAVE_USING_OPERATOR - Success
  -- Performing Test HAVE_NAMESPACES
  -- Performing Test HAVE_NAMESPACES - Success
  -- Performing Test HAVE_GCC_TLS
  -- Performing Test HAVE_GCC_TLS - Success
  -- Performing Test HAVE_MSVC_TLS
  -- Performing Test HAVE_MSVC_TLS - Success
  -- Performing Test HAVE_CXX11_TLS
  -- Performing Test HAVE_CXX11_TLS - Success
  -- Performing Test HAVE_ALIGNED_STORAGE
  -- Performing Test HAVE_ALIGNED_STORAGE - Success
  -- Performing Test HAVE_SYMBOLIZE
  -- Performing Test HAVE_SYMBOLIZE - Failed
  -- Performing Test HAVE_LOCALTIME_R
  -- Performing Test HAVE_LOCALTIME_R - Failed
  -- Configuring done
  -- Generating done
  -- Build files have been written to: D:/INSTALL/Development/lib/ceres-mingw/glog/build
  </code></pre>
  <p>And this is the error output of the mingw32 compilation command:</p>
  <pre><code>D:\INSTALL\Development\lib\ceres-mingw\glog\src\demangle.cc:42:10: fatal error: dbghelp.h: No such file or directory
     42 | #include &lt;dbghelp.h&gt;
        |          ^~~~~~~~~~~
  compilation terminated.
  CMakeFiles\glog.dir\build.make:62: recipe for target 'CMakeFiles/glog.dir/src/demangle.cc.obj' failed
  mingw32-make[2]: *** [CMakeFiles/glog.dir/src/demangle.cc.obj] Error 1
  mingw32-make[2]: *** Waiting for unfinished jobs....
  In file included from D:\INSTALL\Development\lib\ceres-mingw\glog\src\logging.cc:63:
  D:\INSTALL\Development\lib\ceres-mingw\glog\src\windows/dirent.h:383:28: error: missing binary operator before token &quot;(&quot;
    383 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
        |                            ^
  D:\INSTALL\Development\lib\ceres-mingw\glog\src\windows/dirent.h:405:28: error: missing binary operator before token &quot;(&quot;
    405 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
        |                            ^
  D:\INSTALL\Development\lib\ceres-mingw\glog\src\symbolize.cc:877:10: fatal error: dbghelp.h: No such file or directory
    877 | #include &lt;dbghelp.h&gt;
        |          ^~~~~~~~~~~
  compilation terminated.
  In file included from D:\INSTALL\Development\lib\ceres-mingw\glog\src\windows\port.cc:41:
  D:\INSTALL\Development\lib\ceres-mingw\glog\src\windows\port.h:166:14: error: ambiguating new declaration of 'char* strerror_r(int, char*, size_t)'
    166 | inline char* strerror_r(int errnum, char* buf, size_t buflen) {
        |              ^~~~~~~~~~
  In file included from d:\mingw\include\winnt.h:49,
                   from d:\mingw\include\windef.h:269,
                   from d:\mingw\include\windows.h:42,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\windows\port.h:52,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\windows\port.cc:41:
  d:\mingw\include\string.h:223:12: note: old declaration 'int strerror_r(int, char*, size_t)'
    223 | extern int strerror_r (int, char *, size_t);
        |            ^~~~~~~~~~C akeFiles\glog.dir\build.make:104: recipe for target 'CMakeFiles/glog.dir/src/symbolize.cc.obj' failed
  
  mingw32-make[2]: *** [CMakeFiles/glog.dir/src/sy D:\INSTALL\Development\lib\ceres-mingw\glog\src\windows\port.cc:bo In function 'litm* localtime_r(const time_t*, tm*)ze':
  .cD:\INSTALL\Development\lib\ceres-mingw\glog\src\windows\port.cc:53:3:c. oberror: j]' Elocaltime_srr' was not declared in this scope; did you mean 'orlocaltime_r 1'?
     53 |
  localtime_s(result, timep);
        |   ^~~~~~~~~~~
        |   localtime_r
  D:\INSTALL\Development\lib\ceres-mingw\glog\src\windows\port.cc: In function 'tm* gmtime_r(const time_t*, tm*)':
  D:\INSTALL\Development\lib\ceres-mingw\glog\src\windows\port.cc:59:5: error: 'gmtime_s' was not declared in this scope; did you mean 'gmtime_r'?
     59 |     gmtime_s(result, timep);
        |     ^~~~~~~~
        |     gmtime_r
  In file included from D:\INSTALL\Development\lib\ceres-mingw\glog\src\utilities.h:80,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\raw_logging.cc:34:
  D:/INSTALL/Development/lib/ceres-mingw/glog/src/windows/port.h:166:14: error: ambiguating new declaration of 'char* strerror_r(int, char*, size_t)'
    166 | inline char* strerror_r(int errnum, char* buf, size_t buflen) {
        |              ^~~~~~~~~~
  In file included from d:\mingw\include\winnt.h:49,
                   from d:\mingw\include\windef.h:269,
                   from d:\mingw\include\windows.h:42,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\base/mutex.h:129,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\utilities.h:75,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\raw_logging.cc:34:
  d:\mingw\include\string.h:223:12: note: old declaration 'int strerror_r(int, char*, size_t)'
    223 | extern int  MakeFiles\glog.dir\build.make:160: recipe for target 'CMakeFiles/glog.dirstrerror_r/ rc/windows/port.cc.obj' failed
   (int, char *, size_t);
        |            mi^~~~~~~~~~ng
  w32-make[2]: *** [CMakeFiles/glog.dir/src/windows/port.cc.obj] Error 1
  In file included from D:\INSTALL\Development\lib\ceres-mingw\glog\src\utilities.h:80,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\logging.cc:32:
  D:/INSTALL/Development/lib/ceres-mingw/glog/src/windows/port.h:166:14: error: ambiguating new declaration of 'char* strerror_r(int, char*, size_t)'
    166 | inline char* strerror_r(int errnum, char* buf, size_t buflen) {
        |              ^~~~~~~~~~
  In file included from d:\mingw\include\winnt.h:49,
                   from d:\mingw\include\windef.h:269,
                   from d:\mingw\include\windows.h:42,
                   from In file included from                                                                                                                                                                                                                   from ,
                   from                                                                                                                                                                                                                                         from :
                                                                                                                                                                                                                                                                                         ambiguating new declaration of '                                                           '
    166 | inline char*                                                                                                                                                                                                                           223 | extern int (int errnum, char* buf, size_t buflen) {
        |                                                                                                                                                                                                                                            |
  ^~~~~~~~~~
  In file included from d:\mingw\include\winnt.h:49,
                   from d:\mingw\include\windef.h:269,
                   from d:\mingw\include\windows.h:42,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\base/mutex.h:129,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\utilities.h:75,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\utilities.cc:32:
  d:\mingw\include\string.h:223:12: note: old declaration 'int strerror_r(int, char*, size_t)'
    223 | extern int strerror_r (int, char *, size_t);
        |            ^~~~~~~~~~
  In file included from D:\INSTALL\Development\lib\ceres-mingw\glog\src\utilities.h:80,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\signalhandler.cc:34:
  D:/INSTALL/Development/lib/ceres-mingw/glog/src/windows/port.h:166:14: error: ambiguating new declaration of 'char* strerror_r(int, char*, size_t)'
    166 | inline char* strerror_r(int errnum, char* buf, size_t buflen) {
        |              ^~~~~~~~~~
  In file included from d:\mingw\include\winnt.h:49,
                   from d:\mingw\include\windef.h:269,
                   from d:\mingw\include\windows.h:42,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\base/mutex.h:129,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\utilities.h:75,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\signalhandler.cc:34:
  d:\mingw\include\string.h:223:12: note: old declaration 'int strerror_r(int, char*, size_t)'
    223 | extern int strerror_r (int, char *, size_t);
        |            ^~~~~~~~~~
  CMakeFiles\glog.dir\build.make:90: recipe for target 'CMakeFiles/glog.dir/src/raw_logging.cc.obj' failed
  mingw32-make[2]: *** [CMakeFiles/glog.dir/src/raw_logging.cc.obj] Error 1
  CMakeFiles\glog.dir\build.make:118: recipe for target 'CMakeFiles/glog.dir/src/utilities.cc.obj' failed
  mingw32-make[2]: *** [CMakeFiles/glog.dir/src/utilities.cc.obj] Error 1
  In file included from In file included from D:\INSTALL\Development\lib\ceres-mingw\glog\src\logging.cc:63                                                              ,
                   from :
  D:\INSTALL\Development\lib\ceres-mingw\glog\src\vlog_is_on.cc:35D:\INSTALL\Development\lib\ceres-mingw\glog\src\windows/dirent.h::
   In function 'D:/INSTALL/Development/lib/ceres-mingw/glog/src/windows/port.h:166:14:_WDIR* _wopendir(const wchar_t*) ':
  error: D:\INSTALL\Development\lib\ceres-mingw\glog\src\windows/dirent.h:413:5:ambiguating new declaration of ' char* strerror_r(int, char*, size_t)error: '
    166 | inline char* 'strerror_rwcsncpy_s(int errnum, char* buf, size_t buflen) {
        |              ' was not declared in this scope; did you mean '^~~~~~~~~~wcsncpy
  '?
    413 |     In file included from                                                                                                                                                                                                                  |     ,
                   from                                                                                                                                                                                                                              |     ,
                   from                                                                                                                                                                                                                        ,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\base/mutex.h:129,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\utilities.h:75,
                   from D:\INSTALL\Development\lib\ceres-mingw\glog\src\vlog_is_on.cc:35:
  d:\mingw\include\string.h:223:12: note: old declaration 'int strerror_r(int, char*, size_t)'
    223 | extern int strerror_r (int, char *, size_t);
        |            ^~~~~~~~~~
  CMakeFiles\glog.dir\build.make:146: recipe for target 'CMakeFiles/glog.dir/src/signalhandler.cc.obj' failed
  mingw32-make[2]: *** [CMakeFiles/glog.dir/src/signalhandler.cc.obj] Error 1
  D:\INSTALL\Development\lib\ceres-mingw\glog\src\logging.cc: In function 'void google::TruncateLogFile(const char*, google::int64, google::int64)':
  D:\INSTALL\Development\lib\ceres-mingw\glog\src\logging.cc:2266:11: error: 'truncate' was not declared in this scope; did you mean 'ftruncate'?
   2266 |       if (truncate(path, 0) == -1) {
        |           ^~~~~~~~
        |           ftruncate
  CMakeFiles\glog.dir\build.make:132: recipe for target 'CMakeFiles/glog.dir/src/vlog_is_on.cc.obj' failed
  mingw32-make[2]: *** [CMakeFiles/glog.dir/src/vlog_is_on.cc.obj] Error 1
  CMakeFiles\glog.dir\build.make:76: recipe for target 'CMakeFiles/glog.dir/src/logging.cc.obj' failed
  mingw32-make[2]: *** [CMakeFiles/glog.dir/src/logging.cc.obj] Error 1
  CMakeFiles\Makefile2:926: recipe for target 'CMakeFiles/glog.dir/all' failed
  mingw32-make[1]: *** [CMakeFiles/glog.dir/all] Error 2
  Makefile:161: recipe for target 'all' failed
  mingw32-make: *** [all] Error 2
  D:\INSTALL\Development\lib\ceres-mingw\glog\build&gt;
  </code></pre>
  <p>I use cmake version 3.15.4 and the official mingw32, as indicated below:</p>
  <pre><code>C:\Users\plamen&gt;&quot;D:\Program Files\CMake\bin\cmake.exe&quot; --version
  cmake version 3.15.4
  
  CMake suite maintained and supported by Kitware (kitware.com/cmake).
  
  C:\Users\plamen&gt;mingw32-make,exe --version
  GNU Make 3.82.90
  Built for i686-pc-mingw32
  Copyright (C) 1988-2012 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.
  </code></pre>
  <p>Does any body can help me solving this problem?</p>