google / glog

C++ implementation of the Google logging module
http://google.github.io/glog/
BSD 3-Clause "New" or "Revised" License
7.1k stars 2.07k forks source link

Windows cmake build failed when using msys2 #1124

Closed Illia-Vidanov closed 3 months ago

Illia-Vidanov commented 3 months ago

So I was folowing the exact steps described in manual

>git clone https://github.com/google/glog
Cloning into 'glog'...

>cd glog

>cmake -S . -B build -G "Unix Makefiles"
-- The CXX compiler identification is GNU 14.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /ucrt64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find GTest (missing: GTest_DIR)
CMake Warning at CMakeLists.txt:78 (find_package):
  By not providing "Findgflags.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "gflags", but
  CMake did not find one.

  Could not find a package configuration file provided by "gflags" (requested
  version 2.2.2) with any of the following names:

    gflagsConfig.cmake
    gflags-config.cmake

  Add the installation prefix of "gflags" to CMAKE_PREFIX_PATH or set
  "gflags_DIR" to a directory containing one of the above files.  If "gflags"
  provides a separate development package or SDK, be sure it has been
  installed.

-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Could NOT find Unwind (missing: Unwind_INCLUDE_DIR Unwind_LIBRARY)
-- Looking for C++ include dlfcn.h
-- Looking for C++ include dlfcn.h - not found
-- Looking for C++ include elf.h
-- Looking for C++ include elf.h - not found
-- Looking for C++ include glob.h
-- Looking for C++ include glob.h - not found
-- Looking for C++ include link.h
-- Looking for C++ include link.h - not found
-- Looking for C++ include pwd.h
-- Looking for C++ include pwd.h - not found
-- Looking for C++ include sys/exec_elf.h
-- Looking for C++ include sys/exec_elf.h - not found
-- Looking for C++ include sys/syscall.h
-- Looking for C++ include sys/syscall.h - not found
-- Looking for C++ include sys/time.h
-- Looking for C++ include sys/time.h - found
-- Looking for C++ include sys/types.h
-- Looking for C++ include sys/types.h - found
-- Looking for C++ include sys/utsname.h
-- Looking for C++ include sys/utsname.h - not found
-- Looking for C++ include sys/wait.h
-- Looking for C++ include sys/wait.h - not found
-- Looking for C++ include syscall.h
-- Looking for C++ include syscall.h - not found
-- Looking for C++ include syslog.h
-- Looking for C++ include syslog.h - not found
-- Looking for C++ include ucontext.h
-- Looking for C++ include ucontext.h - not found
-- Looking for C++ include unistd.h
-- Looking for C++ include unistd.h - found
-- Looking for C++ include stdint.h
-- Looking for C++ include stdint.h - found
-- Looking for C++ include stddef.h
-- Looking for C++ include stddef.h - found
-- Check size of mode_t
-- Check size of mode_t - done
-- Check size of ssize_t
-- Check size of ssize_t - done
-- Looking for dladdr
-- Looking for dladdr - not found
-- Looking for fcntl
-- Looking for fcntl - not found
-- Looking for posix_fadvise
-- Looking for posix_fadvise - 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
-- Looking for backtrace
-- Looking for backtrace - not found
-- Looking for backtrace_symbols
-- Looking for backtrace_symbols - not found
-- Looking for _chsize_s
-- Looking for _chsize_s - found
-- Looking for UnDecorateSymbolName
-- Looking for UnDecorateSymbolName - found
-- Looking for abi::__cxa_demangle
-- Looking for abi::__cxa_demangle - found
-- Looking for __argv
-- Looking for __argv - found
-- Looking for getprogname
-- Looking for getprogname - not found
-- Looking for program_invocation_short_name
-- Looking for program_invocation_short_name - not found
-- Performing Test HAVE___PROGNAME
-- Performing Test HAVE___PROGNAME - Failed
-- Performing Test HAVE_SYMBOLIZE
-- Performing Test HAVE_SYMBOLIZE - Failed
-- Looking for gmtime_r
-- Looking for gmtime_r - not found
-- Looking for localtime_r
-- Looking for localtime_r - not found
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done (32.6s)
-- Generating done (1.9s)
-- Build files have been written to: /c/path/glog/build

>cmake --build build
[  2%] Building CXX object CMakeFiles/glog_internal.dir/src/demangle.cc.o
In file included from C:/Programming/msys2/ucrt64/include/dbghelp.h:17,
                 from C:/Users/╨esktop/temp/glog/src/demangle.cc:50:
C:/Programming/msys2/ucrt64/include/psdk_inc/_dbg_LOAD_IMAGE.h:24:5: error: 'PSTR' does not name a type
   24 |     PSTR ModuleName;
      |     ^~~~
C:/Programming/msys2/ucrt64/include/psdk_inc/_dbg_LOAD_IMAGE.h:25:5: error: 'HANDLE' does not name a type
   25 |     HANDLE hFile;

... whole lot of this kind of errors (full list)[https://pastebin.com/qYh8vmAy]

C:/path/glog/src/demangle.cc: In function 'bool google::glog_internal_namespace_::Demangle(const char*, char*, size_t)':
C:/path/glog/src/demangle.cc:1336:10: error: 'UnDecorateSymbolName' was not declared in this scope
 1336 |   return UnDecorateSymbolName(mangled, out, out_size, UNDNAME_COMPLETE);
      |          ^~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/glog_internal.dir/build.make:76: CMakeFiles/glog_internal.dir/src/demangle.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:865: CMakeFiles/glog_internal.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

I also tried building gflags separatelly and adding gflags_DIR like this: >cmake -S . -B build -G "Unix Makefiles" -Dgflags_DIR="/c/path/gflags/build" but the only differance was that it didn't print the warning

And here is some more envoriment info:

>cmake --version
cmake version 3.30.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

>g++ --version
g++ (Rev1, Built by MSYS2 project) 14.2.0
Copyright (C) 2024 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.`

>path
PATH=
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\WINDOWS\System32\OpenSSH\;
C:\Program Files\Git\cmd;
C:\Programming\msys2;
C:\Programming\msys2\usr\bin;
C:\Programming\msys2\ucrt64\bin;

Also no google packages are installed by msys2, I know I can install and use them using msys2's package manager, but I wounder why can't I do it using cmake. The same problem arises when library is included using 'sub_dirctory' inside of my project's CMakeLists.txt

sergiud commented 3 months ago

Looks like an issue in msys2 ucrt64 headers. dbghelp.h either does not see or purposefully does not include standard typedefs.

Does the issue go away if you add #include <windows.h> at the top of src/demangle.cc just before dbghelp.h is included?

Illia-Vidanov commented 3 months ago

Thanks for reply! Yes it solves the issue with dbghelp.h, but I guess it's not the only issue with msys2 headers. They also doesn't contain declarations for localtime_r and gmtime_r, as well as for strerror_r (which is a gnu extension?) for logging.cc file I also tried compiling it using msys2's mingw64 compiler and by freshly installed default mingw64 compiler from github but still same errors about localtime_r gmtime_r and strerror_r:

C:/path/glog/src/logging.cc:1128:7: error: 'gmtime_r' was not declared in this scope; did you mean 'gmtime_s'?
 1128 |       gmtime_r(&t, &tm_time);
      |       ^~~~~~~~
      |       gmtime_s
C:/path/glog/src/logging.cc:1130:7: error: 'localtime_r' was not declared in this scope; did you mean 'localtime_s'?
 1130 |       localtime_r(&t, &tm_time);
      |       ^~~~~~~~~~~
      |       localtime_s
C:/path/glog/src/logging.cc: In function 'int google::posix_strerror_r(int, char*, size_t)':
C:/path/glog/src/logging.cc:2486:38: error: 'strerror_r' was not declared in this scope; did you mean 'strerror_s'?
 2486 |   char* rc = reinterpret_cast<char*>(strerror_r(err, buf, len));
      |                                      ^~~~~~~~~~
      |                                      strerror_s
...

full

sergiud commented 3 months ago

Our mingw64 and mingw32 CI builds compile without issues. I guess you are using msys2 POSIX compatible GCC (i.e., without setting MSYSTEM). That's not supported at the moment.

Illia-Vidanov commented 3 months ago

Thank you very much! finally I know what is wrong with my programming envoriment)