Skip to content

Commit d679297

Browse files
committed
fix(flags): MinGW default links -static — the piecemeal winpthread recipe loses to driver implicit libs
CI import table still showed libwinpthread-1.dll after -Wl,-Bstatic -lwinpthread; winlibs' documented answer for standalone exes is a full -static link (system DLLs still resolve via import libs). Gated on staticStdlib so [build] static_stdlib=false opts out.
1 parent 485b0c3 commit d679297

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/build/flags.cppm

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,19 @@ CompileFlags compute_flags(const BuildPlan& plan) {
347347
std::string mingw_static;
348348
std::string mingw_stdexp;
349349
if (caps.stdlib_id == "libstdc++") {
350-
if (f.linkage == "static") mingw_static = " -static";
350+
// `-static` for the whole link — winlibs' own recommendation for
351+
// standalone exes. The piecemeal recipe (-static-libstdc++ +
352+
// -Wl,-Bstatic -lwinpthread) verifiably loses to the driver's
353+
// implicit closing libs: CI import tables still showed
354+
// libwinpthread-1.dll. System DLLs (KERNEL32/UCRT) still resolve
355+
// via their import libs. Tied to staticStdlib so
356+
// [build] static_stdlib=false opts back into DLL-coupled links.
357+
if (f.staticStdlib || f.linkage == "static")
358+
mingw_static = " -static";
351359
// std::print's terminal probe (__open_terminal /
352360
// __write_to_terminal, bits/print.h) lives in libstdc++exp.a on
353-
// Windows targets — plain -lstdc++ leaves them undefined. And
354-
// POSIX-threads libstdc++ (winlibs) pulls libwinpthread-1.dll
355-
// unless winpthread is forced static — the classic third DLL
356-
// that -static-libstdc++/-static-libgcc do NOT cover.
357-
mingw_stdexp = " -lstdc++exp -Wl,-Bstatic -lwinpthread -Wl,-Bdynamic";
361+
// Windows targets — plain -lstdc++ leaves them undefined.
362+
mingw_stdexp = " -lstdc++exp";
358363
}
359364
f.ld = std::format("{}{}{}{}{}{}", mingw_static, static_stdlib, b_flag,
360365
user_ldflags, mingw_stdexp, link_extra);

0 commit comments

Comments
 (0)