Is it as expected when "-Cdefault-linker-libraries=off" used but rustc passes some system libs to link.exe?

When building a demo, I found that even if adding the config below to .cargo/config.toml, rustc would still pass "bcrypt.lib" "advapi32.lib" "kernel32.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "msvcrt.lib" "legacy_stdio_definitions.lib" to link.exe.

[target.i686-pc-windows-msvc]
rustflags = [
    "-C", "default-linker-libraries=off",
]

It seems default-linker-libraries=off is currently a no-op for msvc targets. There may be a reason for this or it may be it was just never implemented. The documentation is a little vague on what the option is actually intended to do, other than.it causes -nodefautlibs to be passed to gnu linkers. The Windows MSVC linker has a similar sounding flag but it works a bit differently. It disables any libs added with the /DEFAULTLIB: option but Rust does not currently link libraries that way so it wouldn't do anything in any case.

You could try asking on zulip or try opening an issue on the rust repository with a suggestion on how you think the flag should work for Windows, or at least for the docs to be clarified. I'm sure someone will have more background information to share.

Thanks, an issue added.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.