How to pass linker options to `cargo build`?

I am trying to profile my Rust application on Windows using Visual Studio, but MSVC requires the linker option /PROFILE to be enabled.

What this does is enable several flags:

/OPR:REF and /OPT:NOICF should be set when you set debug = true for a profile. Similarly, /INCREMENTAL:NO should be set when incremental = false.

Unfortunately, by default /FIXED:NO only applies for DLLs. The only option I have is to manually pass linker options to rustc at this point (either /PROFILE or /FIXED:NO).

How can you pass linker options to a cargo build command?

How can you pass linker options to a cargo build command?

RUSTFLAGS=-Clink-arg=/PROFILE cargo build.

/OPR:REF and /OPT:NOICF should be set when you set debug = true for a profile. Similarly, /INCREMENTAL:NO should be set when incremental = false .

/OPT:REF,NOICF is passed when optimizations are disables:

Incremental linking is not supported by rustc, so /INCREMENTAL:YES is never set.

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.