You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a Cargo package contains both a binary crate and a library crate, linker arguments from the build script are used only when building the library crate.
Next, run touch src/lib.rs to create an empty library crate. Then build again.
This fails with a linker error when linking the binary. Note that Cargo passes -l z to rustc when compiling src/lib.rs but not when compiling src/main.rs:
When a Cargo package contains both a binary crate and a library crate, linker arguments from the build script are used only when building the library crate.
Originally reported at: https://users.rust-lang.org/t/cant-compile-gtk-hello-world-app/44404
Steps to reproduce:
On a system with zlib installed, run
cargo new empty
to create a new binary project. Add abuild.rs
file with the following contents:Replace
src/main.rs
with the following code:This builds successfully. Note that Cargo passes
-l z
to rustc when compilingsrc/main.rs
:Next, run
touch src/lib.rs
to create an empty library crate. Then build again.This fails with a linker error when linking the binary. Note that Cargo passes
-l z
to rustc when compilingsrc/lib.rs
but not when compilingsrc/main.rs
:Proposed solution
Cargo should pass linker arguments from the build script to rustc for all targets of the package.
The text was updated successfully, but these errors were encountered: