About #pragma comment linker in Rust

#pragma comment(linker, "/merge:. data=. text")
#pragma comment(linker, "/merge:. rdata=. text")
#pragma comment(linker, "/section:. rdata=. text")

How should I implement it in rust? please

With a build script, you can pass linker arguments.

I'm also the author of a crate wrapping the textual API with a procedural one:


For the specific case of just linking a native library, you can use the #[link] attribute.


To do exactly the same as this, you can use #[link_section = ".drectve"], like in this bug report: Windows `rust-lld` does not support the MSVC `manifestdependency` `.drectve` · Issue #85642 · rust-lang/rust · GitHub

cargo rustc -- -C link-args="/merge:.data=.text /merge:.rdata=.text /section:.text,RWE"

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.