On Thu, 17 Jul 2025, Pali Rohár wrote:
When mingw-w64 is compiled with LTO support (-flto and -ffat-lto-objects in CFLAGS and LDFLAGS) then simple C applicationint main(void) { return 0; } cause LTO compile warning: $ gcc test.c -o test.exe -flto ./include/internal.h:113:17: warning: type of ‘main’ does not match original declaration [-Wlto-type-mismatch] test.c:1:5: note: type mismatch in parameter 1 int main(void) { return 0; } ^ test.c:1:5: note: type ‘void’ should match type ‘int’ test.c:1:5: note: ‘main’ was previously declared here This is because internal.h defines main as: int __CRTDECL main(int _Argc, char **_Argv, char **_Env); Which does not match the main in test.c application. Function main is somehow special that it can take from zero to three parameters. So define it in internal.h file without parameters. This will mute the gcc LTO warning which is printed by default. Same applies for wmain() function. --- mingw-w64-crt/include/internal.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mingw-w64-crt/include/internal.h b/mingw-w64-crt/include/internal.h index 997a89b189a1..e68296a4123f 100644 --- a/mingw-w64-crt/include/internal.h +++ b/mingw-w64-crt/include/internal.h @@ -110,8 +110,11 @@ extern "C" { int __CRTDECL _wsetargv(void); int __CRTDECL __wsetargv(void); - int __CRTDECL main(int _Argc, char **_Argv, char **_Env); - int __CRTDECL wmain(int _Argc, wchar_t **_Argv, wchar_t **_Env); + /* Do not define main parameters because then it cause LTO compile + * warning (-Wlto-type-mismatch) about mismatches parameters when + * application defines main as: int main(void) { ... } */ + int __CRTDECL main(/*int _Argc, char **_Argv, char **_Env*/); + int __CRTDECL wmain(/*int _Argc, wchar_t **_Argv, wchar_t **_Env*/);
How does this behave if compiling things in C23 mode (I guess both mingw-w64-crt and the end user application)? In C23, an empty parameter list, func(), should be equivalent to func(void), while it in earlier language versions allowed any number of parameters.
(Also, I'm aware of your other older patches awaiting response - I'm currently vacationing so I don't have enough bandwidth to dig through all of my review backlog.)
// Martin _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
