Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running a binary built by cargo fails due to missing libraries; but cargo running it works #47931

Open
staktrace opened this issue Feb 1, 2018 · 9 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue.

Comments

@staktrace
Copy link
Contributor

STR (using latest stable rust 1.23.0 on Ubuntu 16.04):

  1. Clone the cbindgen repo (current master is 270491f)
  2. Build it using cargo build --release
  3. Run it by running target/release/cbindgen
  4. Run it by running cargo run --release

Expected:
step 3 and step 4 both run the binary without errors

Actual:
Step 4 runs the binary. But step 3 produces this error:

target/release/cbindgen: error while loading shared libraries: libproc_macro-6572f0cb64bf7b5a.so: cannot open shared object file: No such file or directory

That .so file doesn't appear in the target directory.

/cc @eqrion who was seeing this also.

@gsollazzo gsollazzo added T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. labels Feb 1, 2018
@gsollazzo
Copy link
Member

I can replicate the problem on OSX on nightly [rustc 1.25.0-nightly (90eb44a 2018-01-29)].

@retep998
Copy link
Member

retep998 commented Feb 2, 2018

This is a general issue with any crate that depends on internal rustc crates.

One way to solve this is with my ideal solution, which is to trash the whole dylib plugin infrastructure and instead have all the rustc internal libraries be normal rlibs with procedural macros being cdylibs (or separate binaries entirely with IPC).

@fschutt
Copy link
Contributor

fschutt commented Feb 7, 2018

Is there any workaround yet?

EDIT: For people coming from google, run this:

export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH

see: rust-lang/rustfmt#1687 (comment)

@staktrace
Copy link
Contributor Author

/cc @dtolnay - retep998's comment above makes it sound like cbindgen somehow depends on an internal rustc crate. The error message refers to libproc-macro, which I assume is pulled in via proc-macro2 in the syn and quote dependency lists. However reading the proc-macro2 documentation, it sounds like using proc-macro2 without the nightly feature should use it in a standalone mode that doesn't require internal rustc crates. Is my understanding correct? I'm just trying to figure out if there's a way to break this dependency so that we can publish a new version of cbindgen that is usable without LD_LIBRARY_PATH hacking.

@staktrace
Copy link
Contributor Author

If #48217 gets merged then fixing this should be as easy as setting rpath=true in the Cargo.toml of the app (e.g. cbindgen in this case).

fitzgen added a commit to fitzgen/rust-bindgen that referenced this issue Feb 14, 2018
This reverts commit 6899c27.

The `proc_macro2` crate depends on rustc internal crates, which means that
`bindgen` would need to be run under `rustup`.

We can follow rust-lang/rust#47931 to get updates on
when this issue might be resolved and we can update `quote` again.

Fixes rust-lang#1248
@retep998
Copy link
Member

retep998 commented Feb 15, 2018

It would only "fix" it on platforms that have rpath. Windows users would be left out in the cold.

@steveklabnik
Copy link
Member

Triage: the sysroot system hasn't changed at all.

@mati865
Copy link
Contributor

mati865 commented Jul 23, 2019

It works fine on Linux nightly.

Steps for verification:

  1. git clone https://github.com/eqrion/cbindgen/
  2. cd cbindgen
  3. git checkout 270491f
  4. cargo +nightly build --release
  5. target/release/cbindgen

@bjorn3
Copy link
Member

bjorn3 commented Jul 29, 2023

There are three options here: Setting LD_LIBRARY_PATH, using rustup run (which sets LD_LIBRARY_PATH internally) or compiling with -Crpath (doesn't work on Windows and doesn't allow moving the final executable or the rust toolchain)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants