How can I specify linker flags/arguments in a build script?

This feature has been added to Cargo and was stabilized in Cargo 1.56. The accepted answer is now out-of-date.

Linker arguments can be specified in build.rs like so:

// Pass `-fopenmp` to the linker.
println!("cargo:rustc-link-arg=-fopenmp");

Leave a Comment