Expose dlopen error when failing to load a proc-macro.
@catilac is already working on this.
Since May 24, 2026.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
git clone https://github.com/gmorenz/shared_proc_macro_dep/
cd shared_proc_macro_dep/user
cargo build
Or instead of using cargo since I've just opened https://github.com/rust-lang/cargo/issues/16356 to change cargo's behavior.
cd shared_proc_macro_dep
rustc --crate-type dylib --edition 2024 -C prefer-dynamic --crate-name shared_dep shared_dep/src/lib.rs
rustc --crate-type proc-macro --edition 2024 -C prefer-dynamic --extern shared_dep=libshared_dep.so --crate-name macone macone/src/lib.rs
rustc --crate-type proc-macro --edition 2024 -C prefer-dynamic --extern shared_dep=libshared_dep.so --crate-name mactwo mactwo/src/lib.rs
rustc --crate-type bin --edition 2024 --extern macone=libmacone.so --extern mactwo=libmactwo.so --crate-name usertwo user/src/main.rs
Current output
error[E0463]: can't find crate for `macone`
--> user/src/main.rs:1:1
|
1 | macone::macone!();
| ^^^^^^ can't find crate
[...]
Desired output
Something about failing to load macone, not just telling us that we failed to find it. If dlopen gives us a useful error message, that. Otherwise the fact that dlopen failed.
Rationale and extra context
What's happening here is that cargo isn't passing the right LD_LIBRARY_PATH to load our shared dep to the version of rustc which tries to use the proc macro, so rustc can't make use of it. Passing an appropriate LD_LIBRARY_PATH ourselves solves this problem - but isn't something rustc can do itself.
It can and probably should tell us that it failed to load the proc macro, and not just that it failed to find.
Rust Version
$ rustc --version --verbose
rustc 1.93.0-nightly (646a3f8c1 2025-12-02)
binary: rustc
commit-hash: 646a3f8c15baefb98dc6e0c1c1ba3356db702d2a
commit-date: 2025-12-02
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5
$ cargo --version
cargo 1.93.0-nightly (2a7c49606 2025-11-25)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.