msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.31k stars 1.23k forks source link

Warnings with double define with last updates #10782

Closed gerard-durand closed 2 years ago

gerard-durand commented 2 years ago

I updated with pacman my msys2/mingw64 installation. When I compile some of my projects I obtain warnings concerning double #defines :

C:\MinGW64\include/winbase.h:1983: warning: "FindResource" redefined 1983 #define FindResource __MINGW_NAME_AW(FindResource)

In file included from C:\MinGW64\include/winbase.h:24, from C:\MinGW64\include/windows.h:70, ... C:\MinGW64\include\libloaderapi.h|110|note: this is the location of the previous definition|

define FindResource FindResourceW

or

C:\MinGW64\include/winbase.h:1985: warning: "EnumResourceNames" redefined 1985 #define EnumResourceNames __MINGW_NAME_AW(EnumResourceNames)

In file included from C:\MinGW64\include/winbase.h:24, from C:\MinGW64\include/windows.h:70, from C:\MinGW64\include/winsock2.h:23, from C:\wxWidgets-3.1.6_git\include/wx/msw/wrapwin.h:46, from C:\wxWidgets-3.1.6_git\include/wx/msw/init.h:27, from C:\wxWidgets-3.1.6_git\include/wx/init.h:58, from C:\wxWidgets-3.1.6_git\include/wx/app.h:23, ... C:\MinGW64\include\libloaderapi.h|109|note: this is the location of the previous definition|

define EnumResourceNames EnumResourceNamesW

Before this update, winbase.h and libloaderapi.h where located in C:\msys64\mingw64\x86_64-w64-mingw32\include. Header files have been moved to C:\msys64\mingw64\include. Could it be the reason ?

winbase.h and libloaderapi.h are not called directly in my software, but indirectly through wxWidgets I think.

My software continue to work but these warnings happens many times in compilation.

Biswa96 commented 2 years ago

C:\MinGW64 is not a path from msys2.

gerard-durand commented 2 years ago

Yes it is, because I use a junction between C:\MinGW64 and C:\msys64\mingw64 (made with linkshellextension). This has been working for many years on my PC, so it's certainly not the problem.

Biswa96 commented 2 years ago

Yes, those are defined twice in mingw-w64 headers. But I can not reproduce the issue with a minimal example. Here is a sample code:

#include <windows.h>

int main()
{
    FindResource(NULL, NULL, NULL);
    EnumResourceNames(NULL, NULL, NULL, 0);
}

It compiles with both gcc -Wall test.c and gcc -Wall -DUNICODE -D_UNICODE test.c commands. Let me ask this in upstream.

gerard-durand commented 2 years ago

I have tried your example under my IDE, Code::Blocks. It compiles normally, no warnings. I also tried adding -DUNICODE and -D_UNICODE, adding also #include in the code. Still no problems. So, it's more complicated ...

gerard-durand commented 2 years ago

If I comment in libloaderapi.h line 112 and 113, //#define EnumResourceNames EnumResourceNamesW //#define FindResource FindResourceW I don't have anymore warnings in my wxWidgets project. But, I'm not sure it's a god thing...

Biswa96 commented 2 years ago

Yeah, it should be fixed in mingw-w64. But a proper minimal sample code would be great to reproduce the issue and report it in upstream.

gerard-durand commented 2 years ago

Here is a test that demonstrate the problem. It is derived from the opengl samples penguin in wxWidgets. I have deleted many lines. Probably not enough for a minimal test program...

I provide a codeblocks project (.cbp file) but also a makefile that you can use by : mingw32-make -f makefile.gcc mingw32-make -f makefile.gcc clean

It needs a working full installation of wxWidgets 3.1.5, here in C:\wxWidgets-3.1.5, with all sources, includes, dll... I build this in C:\wxWidgets-3.1.5\build\msw by :

mingw32-make -f makefile.gcc -j 4 SHARED=1 MONOLITHIC=1 BUILD=release VENDOR=cb_64 CXXFLAGS="-std=gnu++20" strip ....\lib\gcc_dll\wxmsw315u_gcc_cb_64.dll strip ....\lib\gcc_dll\wxmsw315u_gl_gcc_cb_64.dll

Note : it is the same behavior with wxWidgets 3.1.6 which is still a beta version.

This what I obtain whith the makefife or the codeblocks project :

D:\Users\Gerard\Documents\Programmation\CodeBlocks\test_wxs>mingw32-make -f makefile.gcc
cmd /c if not exist . md .
cmd /c if not exist obj64 md obj64
g++.exe -Wall -pipe -mthreads -D__WXMSW__ -DwxUSE_UNICODE -O2 -std=gnu++20 -m64 -Wno-maybe-uninitialized -Wno-deprecated-enum-enum-conversion  -IC:\wxWidgets-3.1.5\include -IC:\wxWidgets-3.1.5\contrib\include -IC:\wxWidgets-3.1.5\lib\gcc_dll\mswu -IC:\msys64\mingw64\include -c demo_wxsApp.cpp -o obj64\\demo_wxsApp.o
In file included from C:\msys64\mingw64\include/windows.h:70,
                 from C:\wxWidgets-3.1.5\include/wx/msw/wrapwin.h:43,
                 from C:\wxWidgets-3.1.5\include/wx/msw/init.h:27,
                 from C:\wxWidgets-3.1.5\include/wx/init.h:58,
                 from C:\wxWidgets-3.1.5\include/wx/app.h:23,
                 from demo_wxsApp.h:14,
                 from demo_wxsApp.cpp:11:
C:\msys64\mingw64\include/winbase.h:1983: warning: "FindResource" redefined
 1983 | #define FindResource __MINGW_NAME_AW(FindResource)
      |
In file included from C:\msys64\mingw64\include/winbase.h:24,
                 from C:\msys64\mingw64\include/windows.h:70,
                 from C:\wxWidgets-3.1.5\include/wx/msw/wrapwin.h:43,
                 from C:\wxWidgets-3.1.5\include/wx/msw/init.h:27,
                 from C:\wxWidgets-3.1.5\include/wx/init.h:58,
                 from C:\wxWidgets-3.1.5\include/wx/app.h:23,
                 from demo_wxsApp.h:14,
                 from demo_wxsApp.cpp:11:
C:\msys64\mingw64\include/libloaderapi.h:113: note: this is the location of the previous definition
  113 | #define FindResource FindResourceW
      |
In file included from C:\msys64\mingw64\include/windows.h:70,
                 from C:\wxWidgets-3.1.5\include/wx/msw/wrapwin.h:43,
                 from C:\wxWidgets-3.1.5\include/wx/msw/init.h:27,
                 from C:\wxWidgets-3.1.5\include/wx/init.h:58,
                 from C:\wxWidgets-3.1.5\include/wx/app.h:23,
                 from demo_wxsApp.h:14,
                 from demo_wxsApp.cpp:11:
C:\msys64\mingw64\include/winbase.h:1985: warning: "EnumResourceNames" redefined
 1985 | #define EnumResourceNames __MINGW_NAME_AW(EnumResourceNames)
      |
In file included from C:\msys64\mingw64\include/winbase.h:24,
                 from C:\msys64\mingw64\include/windows.h:70,
                 from C:\wxWidgets-3.1.5\include/wx/msw/wrapwin.h:43,
                 from C:\wxWidgets-3.1.5\include/wx/msw/init.h:27,
                 from C:\wxWidgets-3.1.5\include/wx/init.h:58,
                 from C:\wxWidgets-3.1.5\include/wx/app.h:23,
                 from demo_wxsApp.h:14,
                 from demo_wxsApp.cpp:11:
C:\msys64\mingw64\include/libloaderapi.h:112: note: this is the location of the previous definition
  112 | #define EnumResourceNames EnumResourceNamesW
      |
g++.exe -Wall -pipe -mthreads -D__WXMSW__ -DwxUSE_UNICODE -O2 -std=gnu++20 -m64 -Wno-maybe-uninitialized -Wno-deprecated-enum-enum-conversion  -IC:\wxWidgets-3.1.5\include -IC:\wxWidgets-3.1.5\contrib\include -IC:\wxWidgets-3.1.5\lib\gcc_dll\mswu -IC:\msys64\mingw64\include -c demo_wxsMain.cpp -o obj64\\demo_wxsMain.o
In file included from C:\msys64\mingw64\include/windows.h:70,
                 from C:\wxWidgets-3.1.5\include/wx/msw/wrapwin.h:43,
                 from C:\wxWidgets-3.1.5\include/wx/msw/init.h:27,
                 from C:\wxWidgets-3.1.5\include/wx/init.h:58,
                 from C:\wxWidgets-3.1.5\include/wx/app.h:23,
                 from demo_wxsMain.h:18,
                 from demo_wxsMain.cpp:14:
C:\msys64\mingw64\include/winbase.h:1983: warning: "FindResource" redefined
 1983 | #define FindResource __MINGW_NAME_AW(FindResource)
      |
In file included from C:\msys64\mingw64\include/winbase.h:24,
                 from C:\msys64\mingw64\include/windows.h:70,
                 from C:\wxWidgets-3.1.5\include/wx/msw/wrapwin.h:43,
                 from C:\wxWidgets-3.1.5\include/wx/msw/init.h:27,
                 from C:\wxWidgets-3.1.5\include/wx/init.h:58,
                 from C:\wxWidgets-3.1.5\include/wx/app.h:23,
                 from demo_wxsMain.h:18,
                 from demo_wxsMain.cpp:14:
C:\msys64\mingw64\include/libloaderapi.h:113: note: this is the location of the previous definition
  113 | #define FindResource FindResourceW
      |
In file included from C:\msys64\mingw64\include/windows.h:70,
                 from C:\wxWidgets-3.1.5\include/wx/msw/wrapwin.h:43,
                 from C:\wxWidgets-3.1.5\include/wx/msw/init.h:27,
                 from C:\wxWidgets-3.1.5\include/wx/init.h:58,
                 from C:\wxWidgets-3.1.5\include/wx/app.h:23,
                 from demo_wxsMain.h:18,
                 from demo_wxsMain.cpp:14:
C:\msys64\mingw64\include/winbase.h:1985: warning: "EnumResourceNames" redefined
 1985 | #define EnumResourceNames __MINGW_NAME_AW(EnumResourceNames)
      |
In file included from C:\msys64\mingw64\include/winbase.h:24,
                 from C:\msys64\mingw64\include/windows.h:70,
                 from C:\wxWidgets-3.1.5\include/wx/msw/wrapwin.h:43,
                 from C:\wxWidgets-3.1.5\include/wx/msw/init.h:27,
                 from C:\wxWidgets-3.1.5\include/wx/init.h:58,
                 from C:\wxWidgets-3.1.5\include/wx/app.h:23,
                 from demo_wxsMain.h:18,
                 from demo_wxsMain.cpp:14:
C:\msys64\mingw64\include/libloaderapi.h:112: note: this is the location of the previous definition
  112 | #define EnumResourceNames EnumResourceNamesW
      |
g++.exe -Wall -pipe -mthreads -D__WXMSW__ -DwxUSE_UNICODE -O2 -std=gnu++20 -m64 -Wno-maybe-uninitialized -Wno-deprecated-enum-enum-conversion  -IC:\wxWidgets-3.1.5\include -IC:\wxWidgets-3.1.5\contrib\include -IC:\wxWidgets-3.1.5\lib\gcc_dll\mswu -IC:\msys64\mingw64\include -c dxfrenderer.cpp -o obj64\\dxfrenderer.o
In file included from C:\msys64\mingw64\include/windows.h:70,
                 from C:\wxWidgets-3.1.5\include/wx/msw/wrapwin.h:43,
                 from C:\wxWidgets-3.1.5\include/wx/msw/init.h:27,
                 from C:\wxWidgets-3.1.5\include/wx/init.h:58,
                 from C:\wxWidgets-3.1.5\include/wx/app.h:23,
                 from C:\wxWidgets-3.1.5\include/wx/wx.h:25,
                 from dxfrenderer.cpp:16:
C:\msys64\mingw64\include/winbase.h:1983: warning: "FindResource" redefined
 1983 | #define FindResource __MINGW_NAME_AW(FindResource)
      |
In file included from C:\msys64\mingw64\include/winbase.h:24,
                 from C:\msys64\mingw64\include/windows.h:70,
                 from C:\wxWidgets-3.1.5\include/wx/msw/wrapwin.h:43,
                 from C:\wxWidgets-3.1.5\include/wx/msw/init.h:27,
                 from C:\wxWidgets-3.1.5\include/wx/init.h:58,
                 from C:\wxWidgets-3.1.5\include/wx/app.h:23,
                 from C:\wxWidgets-3.1.5\include/wx/wx.h:25,
                 from dxfrenderer.cpp:16:
C:\msys64\mingw64\include/libloaderapi.h:113: note: this is the location of the previous definition
  113 | #define FindResource FindResourceW
      |
In file included from C:\msys64\mingw64\include/windows.h:70,
                 from C:\wxWidgets-3.1.5\include/wx/msw/wrapwin.h:43,
                 from C:\wxWidgets-3.1.5\include/wx/msw/init.h:27,
                 from C:\wxWidgets-3.1.5\include/wx/init.h:58,
                 from C:\wxWidgets-3.1.5\include/wx/app.h:23,
                 from C:\wxWidgets-3.1.5\include/wx/wx.h:25,
                 from dxfrenderer.cpp:16:
C:\msys64\mingw64\include/winbase.h:1985: warning: "EnumResourceNames" redefined
 1985 | #define EnumResourceNames __MINGW_NAME_AW(EnumResourceNames)
      |
In file included from C:\msys64\mingw64\include/winbase.h:24,
                 from C:\msys64\mingw64\include/windows.h:70,
                 from C:\wxWidgets-3.1.5\include/wx/msw/wrapwin.h:43,
                 from C:\wxWidgets-3.1.5\include/wx/msw/init.h:27,
                 from C:\wxWidgets-3.1.5\include/wx/init.h:58,
                 from C:\wxWidgets-3.1.5\include/wx/app.h:23,
                 from C:\wxWidgets-3.1.5\include/wx/wx.h:25,
                 from dxfrenderer.cpp:16:
C:\msys64\mingw64\include/libloaderapi.h:112: note: this is the location of the previous definition
  112 | #define EnumResourceNames EnumResourceNamesW
      |
windres.exe -i resource.rc -J rc -o obj64\\resource.o -O coff  -IC:\wxWidgets-3.1.5\include -IC:\wxWidgets-3.1.5\contrib\include -IC:\wxWidgets-3.1.5\lib\gcc_dll\mswu -IC:\msys64\mingw64\include
g++.exe  -LC:\wxWidgets-3.1.5\lib\gcc_dll -o .\\demo_wxs.exe obj64\\demo_wxsApp.o obj64\\demo_wxsMain.o obj64\\dxfrenderer.o obj64\\resource.o  -O2 -s -m64 -lopengl32 -lglu32 -mthreads  -lwxmsw31u_gl -lwxmsw31u

D:\Users\Gerard\Documents\Programmation\CodeBlocks\test_wxs>

An interesting thing is that when I change in the makefile at line 18, -IC:\msys64\mingw64\include which is the real include path by -IC:\Mingw64\include which contains a junction on my PC to the real path, I obtain no warnings, with this makefile test_wxs.zip .

gerard-durand commented 2 years ago

Continuing my investigations: completely deleting the include path solves also the problem: no warnings. I think I added it to solve a reference not found in the past... More, C:\msys64\mingw64\include is a path normally implicitly included during a compilation I suppose, and on my system, it's the same thing than C:\MinGW64\include. If I configure my different paths to use only one of these paths to the compiler, it works. It's because, sometimes, I have a mix of the real complete path and the one with a junction, that I meet problems. Strange indeed.