While I think it is possible, IMO it is a problematic solution:

- we need to distinguish between gcc and clang
- in case of clang, we may or may not need linking with libgcc

This first is not really a problem, modern build system allow to do it easily, 
but the second one is probably impossible.

One dirty solution that comes to mind is to build mingw-w64 runtime and after 
locally installing it replace import libraries for kernel32.dll and some others 
Windows DLL with libwindowsapp.a.

- Kirill Makurin

________________________________
From: LIU Hao
Sent: Monday, November 24, 2025 12:34 AM
To: [email protected]; Kirill Makurin
Subject: Re: [Mingw-w64-public] A few questions about UWP apps and 
winstorecompat

在 2025-11-23 22:26, Kirill Makurin 写道:
> Me and Pali had some discussion about this topic, and Pali has pointed out an 
> issue with using -lwindowsapp.
>
> If you look at gcc spec, you will see -lkernel32 following mingw-w64's -l 
> flags. The issue is that this will cause mingw-w64's static code directly 
> reference symbols from kernel32.dll, and not api sets linked with 
> -lwindowsapp. Perfectly, we would want to replace this -lkernel32 with 
> -lwindowsappcompat -lwindowsapp. However, there seems to be no simple way to 
> achieve this.
>
> One way this can be achieved is by getting the specs with `gcc -dumpspecs`, 
> modifying them (with sed, for example) and passing modified specs to gcc with 
> -specs=. I see no simple way how this can be done with build systems like 
> meson or cmake. This also would not work for clang.

Microsoft documentation seems to say that WindowsApp.lib (in the mingw-w64 
case, libwindowsapp.a) should
be the only library to link, so in that case probably you need to pass 
`-nodefaultlibs` and link
everything explicitly.

With Meson I think it would be something like this, untested:

    cc = meson.get_compiler('c')

    my_exe = executable('my',
               # ... some more arguments ...
               dependencies: [
                 cc.find_library('gcc'),
                 cc.find_library('gcc_eh'),
                 cc.find_library('mingw32'),
                 cc.find_library('mingwex'),
                 cc.find_library('msvcrt'),
                 cc.find_library('windowsapp') ],
               link_args: [ '-nodefaultlibs' ],
               override_options: { 'c_winlibs': [] })



--
Best regards,
LIU Hao

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to