Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed compiler warnings and errors under MSYS2+MINGW64 platform. #186

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

gpalino
Copy link
Contributor

@gpalino gpalino commented Oct 21, 2024

Fixed compiler warnings and errors under MSYS2+MINGW64 platform.

Copy link
Owner

@jeremy-rifkin jeremy-rifkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to fix issues and open a PR! What's the reason for adding the #ifndef guard for WIN32_LEAN_AND_MEAN? The only time I would expect this to pop up is if a user was using fetch_content and did add_compile_definitions globally.

@gpalino
Copy link
Contributor Author

gpalino commented Oct 21, 2024

I am using cpptrace for extending signal handler in the widelands game - https://github.com/widelands/widelands/
This is snippet from CMakeLists.txt

  include(FetchContent)
  FetchContent_Declare(
    cpptrace
    GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git
    GIT_TAG        v0.7.2 # <HASH or TAG>
  )
  FetchContent_MakeAvailable(cpptrace)
  target_link_libraries(${NAME} cpptrace::cpptrace)

And it results in these compiler issues, which I didn't experience in 0.7.1 version.

$ time ninja -j20
[109/777] Building CXX object _deps/cpptrace-build/CMakeFiles/cpptrace-lib.dir/src/binary/object.cpp.obj
FAILED: _deps/cpptrace-build/CMakeFiles/cpptrace-lib.dir/src/binary/object.cpp.obj
D:\bin\msys64\mingw64\bin\g++.exe -DASIO_STANDALONE -DCPPTRACE_DEMANGLE_WITH_CXXABI -DCPPTRACE_GET_SYMBOLS_WITH_DBGHELP -DCPPTRACE_GET_SYMBOLS_WITH_LIBDWARF -DCPPTRACE_HAS_CXX_EXCEPTION_TYPE -DCPPTRACE_STATIC_DEFINE -DCPPTRACE_UNWIND_WITH_DBGHELP -DGLBINDING_STATIC_DEFINE -DLIBDWARF_STATIC -DMINGW_HAS_SECURE_API -DNGHTTP2_STATICLIB -DNOMINMAX -DPIC -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0601 -D__STDC_FORMAT_MACROS -D__USE_MINGW_ANSI_STDIO -ID:/code/widelands/build/_deps/cpptrace-src/src -ID:/code/widelands/build/_deps/libdwarf-src/src/lib/libdwarf -isystem D:/code/widelands/build/_deps/cpptrace-src/include -isystem D:/code/widelands/build/_deps/cpptrace-build/include -O2 -g -DNDEBUG -fvisibility=hidden -fno-keep-inline-dllexport -Wall -Wextra -Werror=return-type -Wundef -Wuseless-cast -Wmaybe-uninitialized -MD -MT _deps/cpptrace-build/CMakeFiles/cpptrace-lib.dir/src/binary/object.cpp.obj -MF _deps\cpptrace-build\CMakeFiles\cpptrace-lib.dir\src\binary\object.cpp.obj.d -o _deps/cpptrace-build/CMakeFiles/cpptrace-lib.dir/src/binary/object.cpp.obj -c D:/code/widelands/build/_deps/cpptrace-src/src/binary/object.cpp
D:/code/widelands/build/_deps/cpptrace-src/src/binary/object.cpp:19:10: warning: "WIN32_LEAN_AND_MEAN" redefined
   19 |  #define WIN32_LEAN_AND_MEAN
      |          ^~~~~~~~~~~~~~~~~~~
<command-line>: note: this is the location of the previous definition
D:/code/widelands/build/_deps/cpptrace-src/src/binary/object.cpp: In function 'std::string cpptrace::detail::get_module_name(HMODULE)':
D:/code/widelands/build/_deps/cpptrace-src/src/binary/object.cpp:119:51: error: 'system_error' is not a member of 'std'
  119 |                 std::fprintf(stderr, "%s\n", std::system_error(GetLastError(), std::system_category()).what());
      |                                                   ^~~~~~~~~~~~
D:/code/widelands/build/_deps/cpptrace-src/src/binary/object.cpp:119:85: error: 'system_category' is not a member of 'std'
  119 |                 std::fprintf(stderr, "%s\n", std::system_error(GetLastError(), std::system_category()).what());
      |                                                                                     ^~~~~~~~~~~~~~~
D:/code/widelands/build/_deps/cpptrace-src/src/binary/object.cpp:21:1: note: 'std::system_category' is defined in header '<system_error>'; this is probably fixable by adding '#include <system_error>'
   20 |  #include <windows.h>
  +++ |+#include <system_error>
   21 | #endif
D:/code/widelands/build/_deps/cpptrace-src/src/binary/object.cpp: In function 'cpptrace::object_frame cpptrace::detail::get_frame_object_info(cpptrace::frame_ptr)':
D:/code/widelands/build/_deps/cpptrace-src/src/binary/object.cpp:149:47: error: 'system_error' is not a member of 'std'
  149 |             std::fprintf(stderr, "%s\n", std::system_error(GetLastError(), std::system_category()).what());
      |                                               ^~~~~~~~~~~~
D:/code/widelands/build/_deps/cpptrace-src/src/binary/object.cpp:149:81: error: 'system_category' is not a member of 'std'
  149 |             std::fprintf(stderr, "%s\n", std::system_error(GetLastError(), std::system_category()).what());
      |                                                                                 ^~~~~~~~~~~~~~~
D:/code/widelands/build/_deps/cpptrace-src/src/binary/object.cpp:149:81: note: 'std::system_category' is defined in header '<system_error>'; this is probably fixable by adding '#include <system_error>'
[112/777] Building CXX object _deps/cpptrace-build/CMakeFiles/cpptrace-lib.dir/src/from_current.cpp.obj
D:/code/widelands/build/_deps/cpptrace-src/src/from_current.cpp:14:11: warning: "WIN32_LEAN_AND_MEAN" redefined
   14 |   #define WIN32_LEAN_AND_MEAN
      |           ^~~~~~~~~~~~~~~~~~~
<command-line>: note: this is the location of the previous definition
[114/777] Building CXX object _deps/cpptrace-build/CMakeFiles/cpptrace-lib.dir/src/binary/safe_dl.cpp.obj
In file included from D:/code/widelands/build/_deps/cpptrace-src/src/binary/safe_dl.cpp:5:
D:/code/widelands/build/_deps/cpptrace-src/src/platform/program_name.hpp:10:9: warning: "WIN32_LEAN_AND_MEAN" redefined
   10 | #define WIN32_LEAN_AND_MEAN
      |         ^~~~~~~~~~~~~~~~~~~
<command-line>: note: this is the location of the previous definition
[121/777] Building CXX object _deps/cpptrace-build/CMakeFiles/cpptrace-lib.dir/src/utils/utils.cpp.obj
D:/code/widelands/build/_deps/cpptrace-src/src/utils/utils.cpp:5:10: warning: "WIN32_LEAN_AND_MEAN" redefined
    5 |  #define WIN32_LEAN_AND_MEAN
      |          ^~~~~~~~~~~~~~~~~~~
<command-line>: note: this is the location of the previous definition
[123/777] Building CXX object _deps/cpptrace-build/CMakeFiles/cpptrace-lib.dir/src/binary/pe.cpp.obj
D:/code/widelands/build/_deps/cpptrace-src/src/binary/pe.cpp:13:9: warning: "WIN32_LEAN_AND_MEAN" redefined
   13 | #define WIN32_LEAN_AND_MEAN
      |         ^~~~~~~~~~~~~~~~~~~
<command-line>: note: this is the location of the previous definition
[124/777] Building CXX object _deps/cpptrace-build/CMakeFiles/cpptrace-lib.dir/src/platform/dbghelp_syminit_manager.cpp.obj
D:/code/widelands/build/_deps/cpptrace-src/src/platform/dbghelp_syminit_manager.cpp:12:9: warning: "WIN32_LEAN_AND_MEAN" redefined
   12 | #define WIN32_LEAN_AND_MEAN
      |         ^~~~~~~~~~~~~~~~~~~
<command-line>: note: this is the location of the previous definition
[126/777] Building CXX object _deps/cpptrace-build/CMakeFiles/cpptrace-lib.dir/src/symbols/dwarf/dwarf_resolver.cpp.obj
In file included from D:/code/widelands/build/_deps/cpptrace-src/src/symbols/dwarf/dwarf_resolver.cpp:11:
D:/code/widelands/build/_deps/cpptrace-src/src/platform/path.hpp:10:9: warning: "WIN32_LEAN_AND_MEAN" redefined
   10 | #define WIN32_LEAN_AND_MEAN
      |         ^~~~~~~~~~~~~~~~~~~
<command-line>: note: this is the location of the previous definition
[128/777] Building CXX object _deps/cpptrace-build/CMakeFiles/cpptrace-lib.dir/src/symbols/symbols_with_dbghelp.cpp.obj
D:/code/widelands/build/_deps/cpptrace-src/src/symbols/symbols_with_dbghelp.cpp:15:9: warning: "WIN32_LEAN_AND_MEAN" redefined
   15 | #define WIN32_LEAN_AND_MEAN
      |         ^~~~~~~~~~~~~~~~~~~
<command-line>: note: this is the location of the previous definition
ninja: build stopped: subcommand failed.

Attached is the full testing diff for the wideland's master branch
sh.patch

@gpalino
Copy link
Contributor Author

gpalino commented Oct 21, 2024

And a little unrelated question, but there is another class of compiler warnings, when using -Wmissing-include-dirs, like:

[17/677] Building CXX object src/base/CMakeFiles/base_macros.dir/macros.cc.obj
cc1plus.exe: warning: D:/code/widelands/build/_deps/cpptrace-build/include: No such file or directory [-Wmissing-include-dirs]
[21/677] Building CXX object src/CMakeFiles/build_info.dir/build_info.cc.obj
cc1plus.exe: warning: D:/code/widelands/build/_deps/cpptrace-build/include: No such file or directory [-Wmissing-include-dirs]
[22/677] Building CXX object src/base/CMakeFiles/base_exceptions.dir/exceptions.cc.obj
cc1plus.exe: warning: D:/code/widelands/build/_deps/cpptrace-build/include: No such file or directory [-Wmissing-include-dirs]

gcc gets parameter -isystem D:/code/widelands/build/_deps/cpptrace-build/include
Is the missing include directory a "feature" of cmake's FetchContent, or can cpptrace do anything about it?

@gpalino
Copy link
Contributor Author

gpalino commented Oct 23, 2024

Thanks for taking the time to fix issues and open a PR! What's the reason for adding the #ifndef guard for WIN32_LEAN_AND_MEAN? The only time I would expect this to pop up is if a user was using fetch_content and did add_compile_definitions globally.

This is probably the main reason:

$ grep -r '# *define *WIN32_LEAN_AND_MEAN' /mingw64/include
/mingw64/include/ares.h:#    define WIN32_LEAN_AND_MEAN
/mingw64/include/ares.h:#    define WIN32_LEAN_AND_MEAN
/mingw64/include/asio/detail/config.hpp:#   define WIN32_LEAN_AND_MEAN
/mingw64/include/boost/asio/detail/config.hpp:#   define WIN32_LEAN_AND_MEAN
/mingw64/include/boost/beast/_experimental/unit_test/main.ipp:#  define WIN32_LEAN_AND_MEAN
/mingw64/include/boost/iostreams/detail/current_directory.hpp:# define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers
/mingw64/include/boost/iostreams/detail/system_failure.hpp:# define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers
/mingw64/include/boost/regex/v4/w32_regex_traits.hpp:#define WIN32_LEAN_AND_MEAN
/mingw64/include/GL/glcorearb.h:#define WIN32_LEAN_AND_MEAN 1
/mingw64/include/GL/glext.h:#define WIN32_LEAN_AND_MEAN 1
/mingw64/include/GL/wgl.h:#define WIN32_LEAN_AND_MEAN 1
/mingw64/include/GL/wglew.h:#    define WIN32_LEAN_AND_MEAN 1
/mingw64/include/GL/wglext.h:#define WIN32_LEAN_AND_MEAN 1
/mingw64/include/libmodplug/stdafx.h:#define WIN32_LEAN_AND_MEAN
/mingw64/include/pkgconf/libpkgconf/stdinc.h:# define WIN32_LEAN_AND_MEAN
/mingw64/include/python3.11/internal/pycore_condvar.h:#define WIN32_LEAN_AND_MEAN
/mingw64/include/SDL2/SDL_egl.h:#define WIN32_LEAN_AND_MEAN 1
/mingw64/include/SDL2/SDL_opengl.h:#define WIN32_LEAN_AND_MEAN 1
/mingw64/include/SDL2/SDL_opengl_glext.h:#define WIN32_LEAN_AND_MEAN 1
/mingw64/include/SDL2/SDL_syswm.h:#define WIN32_LEAN_AND_MEAN
/mingw64/include/tcl8.6/tcl-private/win/tclWinPort.h:#define WIN32_LEAN_AND_MEAN
/mingw64/include/tk8.6/tk-private/win/tkWin.h:#define WIN32_LEAN_AND_MEAN
/mingw64/include/zconf.h:#      define WIN32_LEAN_AND_MEAN

widelands is using SDL and asio libraries and they define WIN32_LEAN_AND_MEAN. So IMO it is better to not collide with other header definitions and provide guards everywhere.

@jeremy-rifkin
Copy link
Owner

Thanks for clarifying and providing the additional info, I think it's very reasonable to do this special handling for WIN32_LEAN_AND_MEAN. Regarding the -Wmissing-include-dirs warnings, that's not something I've seen before but it might just be a quirk of how FetchContent is doing the build.

Copy link
Owner

@jeremy-rifkin jeremy-rifkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for taking the time to do this!

@jeremy-rifkin jeremy-rifkin merged commit 9269a72 into jeremy-rifkin:main Oct 27, 2024
78 of 79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants