Problem
println!("cargo:rustc-link-arg=-Wl,-export-dynamic"); is respected in binaries but silently ignored when emitted by a library. This can lead to frustrating chasing of mysterious missing symbols. An example of such scenario is when trying to link a crate that integrates OCaml runtime via ocaml-interop.
Steps
- create a binary crate with a build script that emits
cargo:rustc-link-arg=-Wl,-export-dynamic
- observe the build with
cargo -v - the export-dynamic flag is present
- move the build script into a dependency
- observe the build of the binary - the flag is not present
Possible Solution(s)
The simplest would be to just pass the argument but I can understand it might be undesirable, in which case an error message should be emitted. However, if not allowing libraries to emit that argument is desired, it'd be good to have some other way of exporting proper symbols (perhaps by listing them) because it'd be annoying having to add a build script to properly use a dependency.
Notes
This issue was originally filed at rust-lang/rust#155240 where it was determined it's a problem with cargo.
Version
cargo 1.95.0-nightly (f298b8c82 2026-02-24)
release: 1.95.0-nightly
commit-hash: f298b8c82da0cba538516b45b04a480fc501d4c0
commit-date: 2026-02-24
host: x86_64-unknown-linux-gnu
libgit2: 1.9.2 (sys:0.20.4 vendored)
libcurl: 8.15.0-DEV (sys:0.4.83+curl-8.15.0 vendored ssl:OpenSSL/3.5.4)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Debian 12.0.0 (bookworm) [64-bit]
Problem
println!("cargo:rustc-link-arg=-Wl,-export-dynamic");is respected in binaries but silently ignored when emitted by a library. This can lead to frustrating chasing of mysterious missing symbols. An example of such scenario is when trying to link a crate that integrates OCaml runtime viaocaml-interop.Steps
cargo:rustc-link-arg=-Wl,-export-dynamiccargo -v- theexport-dynamicflag is presentPossible Solution(s)
The simplest would be to just pass the argument but I can understand it might be undesirable, in which case an error message should be emitted. However, if not allowing libraries to emit that argument is desired, it'd be good to have some other way of exporting proper symbols (perhaps by listing them) because it'd be annoying having to add a build script to properly use a dependency.
Notes
This issue was originally filed at rust-lang/rust#155240 where it was determined it's a problem with
cargo.Version