4 ms·
> Usually the Zig compiler can generate binaries smaller than MSVC because it doesn't link in a bunch of useless junk from the C Runtime (on Windows, Zig has no
by delta_p_delta_x 2y ago
> Usually the Zig compiler can generate binaries smaller than MSVC because it doesn't link in a bunch of useless junk from the C Runtime (on Windows, Zig has no dependency on the C runtime)
MSVC defaults to linking against the UCRT, just like how Clang and GCC on Linux default to linking against the system libc. This is to provide a reasonably useful C environment as a sane default.
If you don't want UCRT under MSVC, supply `/MT /NODEFAULTLIB /ENTRY:<function-name>` in the command-line invocation (or in the Visual Studio MSBuild options).
It is perfectly possible to build a Win32-only binary that is fully self-contained and only around 1 KiB.
- pjmlp 2y agoAlso UCRT is kind of recent, Windows 10 timeframe.
- account42 2y agoIt's also irrelevant since you could write a native Win32 binary without and crt dependency before it.
- ziml77 2y agoYep I've done that before, it's how I know linking to the C runtime is what bloats the binary. For most real projects I wouldn't disable linking it, but it's fun to see the output get so small.
- account42 2y ago> It is perfectly possible to build a Win32-only binary that is fully self-contained and only around 1 KiB. Good luck actually distributing that binary to users without all the various kinds of scareware in the way yelling DANGER.
- delta_p_delta_x 2y agoThat's a matter of code signing and SmartScreen, both of which are completely orthogonal to how the binary is built.
- account42 2y agoYou may or may not be able to pay the protection money to get around the warnings but it is not at all orthogonal to how the binary is build - the scareware industry (both Microsoft as well as third parties) absolutely despises executables that deviate from the default MSVC output.