在 2026-9-1 15:36, Zhongteng Gui 写道:
Hi, I'd like to ask what is the correct and suggested order of linking mingw-w64 related libs. We currently faced some linking order problems, see [1].Currently: GCC uses "-lmingw32 -lgcc -lgcc_eh -lmingwex -lmsvcrt -lkernel32 -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmingwex -lmsvcrt -lkernel32", which is genrated from "%G %L %G", with %G = "-lmingw32 -lgcc -lgcc_eh -lmingwex -lmsvcrt -lkernel32" and %L = "-lpthread -ladvapi32 -lshell32 -luser32 -lkernel32". This is safe, but may be a little redundant. Clang uses "-lssp_nonshared -lssp -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lkernel32". -lssp_nonshared, -lssp, and -lmoldname is redundant, I've already opened PR to ask for removing them, see [2], [3] and [4]. Rust uses "-lmsvcrt -lmingwex -lmingw32 -lgcc -lmsvcrt -lmingwex -luser32 -lkernel32". This worked before, but failed when we tried to enable `-fstack-protector-strong` to compile mingw-w64-crt itself.
The order of mingwex and mingw32 probably doesn't matter, but both can have a dependency on libgcc. Pure import libraries (kernel32, user32, advapi32, shell32, and so on) should come last.
msvcrt is unfortunate -- we have customized stuff in there, which may require libgcc (e.g. for 64-bit division on i686), but libgcc also calls standard C functions and Windows APIs, which requires repeating msvcrt, kernel32, ... after it. Ideally such customized stuff could be carefully written to avoid any dependencies on libgcc. Maybe 64-bit targets are not affected; I am not sure.
I think the best choice is to use "-Wl,--start-group" and "-Wl,--end-group", but I'm not sure whether it fits for different compilers, and whether it will causes compatiablity issues regarding different ld. Plus, which libraries should be put inside a group is also a problem.
Yes. -- Best regards, LIU Hao
OpenPGP_signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
