在 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

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

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

Reply via email to