1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# The client links Dear ImGui, which is C++. By default mingw links the C++
# runtime dynamically, so the DLL ends up depending on libstdc++-6.dll,
# libgcc_s_seh-1.dll and libwinpthread-1.dll — none of which exist on the
# target machine, so injection fails with "a dependency is missing".
#
# CXXSTDLIB="" stops the cc crate (imgui-sys's build script) from emitting a
# dynamic `-lstdc++`; the link-args below then pull in libstdc++, winpthreads
# and libgcc statically, in an explicit -Bstatic .. -Bdynamic window so the
# toggle actually covers them (a trailing `-static` would land after the
# library and do nothing). The DLL stays self-contained — one file, no install.
# Scoped to the Windows target by name: a bare CXXSTDLIB would also strip the
# C++ stdlib from a Linux build of imgui-sys, where it must link normally.
[env]
CXXSTDLIB_x86_64_pc_windows_gnu = ""
# rustc links through the C driver (gcc), so libstdc++ is not linked unless we
# ask for it, and -static-libstdc++ (a g++-only flag) is ignored. Link the C++
# runtime, libgcc and winpthreads as static archives inside a -Bstatic window,
# wrapped in --start-group so their circular references (__cxa_guard_*,
# __gthr_win32_*, __emutls_get_address) resolve across passes. fputs and the
# rest of the CRT stay dynamic (msvcrt.dll is always present on Windows), so
# only the mingw-specific runtimes get baked in and the DLL is self-contained.
[target.x86_64-pc-windows-gnu]
rustflags = [
"-C", "link-arg=-Wl,-Bstatic",
"-C", "link-arg=-Wl,--start-group",
"-C", "link-arg=-lstdc++",
"-C", "link-arg=-lgcc",
"-C", "link-arg=-lgcc_eh",
"-C", "link-arg=-lwinpthread",
"-C", "link-arg=-lmingwex",
"-C", "link-arg=-lmingw32",
"-C", "link-arg=-lmoldname",
"-C", "link-arg=-lmsvcrt",
"-C", "link-arg=-lkernel32",
"-C", "link-arg=-Wl,--end-group",
"-C", "link-arg=-Wl,-Bdynamic",
]