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

Regression in running tests with custom library search path #4044

Open
Riateche opened this issue May 14, 2017 · 9 comments
Open

Regression in running tests with custom library search path #4044

Riateche opened this issue May 14, 2017 · 9 comments
Labels
A-build-scripts Area: build.rs scripts A-linkage Area: linker issues, dylib, cdylib, shared libraries, so C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@Riateche
Copy link

Steps to reproduce:

  1. Make a crate that links to a native library which is not in system path. The crate's build script adds the library's path using cargo:rustc-link-search=native=.
  2. Make a test in the crate and run it using cargo test.

cargo 0.17 (shipped with rust 1.16.0) successfully runs the test because it adds the library path to LD_LIBRARY_PATH (on Linux).

But cargo 0.18 (shipped with rust 1.17.0) fails to run the test:

Running [path]/[test_name]-f25c1f4d7cd45ca4 --nocapture
[path]/[test_name]-f25c1f4d7cd45ca4: error while loading shared libraries: libctrt1.so: cannot open shared object file: No such file or directory

It doesn't add the library path to LD_LIBRARY_PATH anymore. The binary is linked successfully because cargo probably still supplies the path to the linker, but it's not enough to run the binary.

@alexcrichton
Copy link
Member

Cargo was tweaked to not modify LD_LIBRARY_PATH for shared objects found outside the build directory as those tend to be system-level concerns, but do you know whether that's the case here? Is the shared object here inside or outside the build directory?

@Riateche
Copy link
Author

Riateche commented May 15, 2017

In my case, the library is outside the build directory. What was the reason for this tweak? Are there any downsides in the old behavior?

@alexcrichton
Copy link
Member

This was changed in #3651 which has some linked discussion for where this can go awry.

@retep998
Copy link
Member

retep998 commented May 15, 2017

Did the issue fixed by #3651 also occur on Windows and Linux or was it a Mac exclusive issue? If it's the latter, then why did we change the behavior on Windows and Linux to break existing setups?

Frankly, I find it odd that we still conflate directories needed at link time with directories needed at run time. If we created a new cargo: key specifically for directories that need to be added to PATH or equivalent, then I'd have no problem with deprecating cargo:rustc-link-search for that purpose, and we wouldn't need to be discussing whether to add shared objects outside the build directory to PATH.

@carols10cents carols10cents added A-build-scripts Area: build.rs scripts A-linkage Area: linker issues, dylib, cdylib, shared libraries, so C-bug Category: bug labels Oct 3, 2017
@lolgesten
Copy link

I got bitten by this today.

$ echo build.rs
...
    pkg_config::probe_library("openh264").unwrap();
...
$ pkg-config --libs openh264
-L/usr/local/lib -lopenh264

$ cargo test     
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running /usr/src/umar/target/debug/deps/video-3f0ed96ec783fc2e
/usr/src/umar/target/debug/deps/video-3f0ed96ec783fc2e: error while loading 
shared libraries: libopenh264.so.4: cannot open shared object file: No such file or 
directory
error: test failed, to rerun pass '--lib'

Changing the LD_LIBRARY_PATH before running did fix the problem.

@stale
Copy link

stale bot commented Sep 19, 2018

As there hasn't been any activity here in over 6 months I've marked this as stale and if no further activity happens for 7 days I will close it.

I'm a bot so this may be in error! If this issue should remain open, could someone (the author, a team member, or any interested party) please comment to that effect?

The team would be especially grateful if such a comment included details such as:

  • Is this still relevant?
  • If so, what is blocking it?
  • Is it known what could be done to help move this forward?

Thank you for contributing!

(The cargo team is currently evaluating the use of Stale bot, and using #6035 as the tracking issue to gather feedback.)

If you're reading this comment from the distant future, fear not if this was closed automatically. If you believe it's still an issue please leave a comment and a team member can reopen this issue. Opening a new issue is also acceptable!

@stale stale bot added the stale label Sep 19, 2018
@lolgesten
Copy link

This issue should remain open until a team member definitely tells us the current behavior is the correct one. And i seriously dislike the stale bot.

@stale stale bot removed the stale label Sep 19, 2018
@danielpclark
Copy link

danielpclark commented Jun 4, 2019

Thanks for opening this issue.

I have a library named Rutie and I've found that Rust isn't acknowledging linker paths on Rust but it is on Mac… see this issue I opened rust-lang/rust#57550

In the meantime I either symlink or copy the Ruby dynamic library to the target/<profile>/deps dir to get it to work. But for projects that depend on Rutie they once against raise an error about loading shared libraries:

error while loading shared libraries: libruby.so.2.6: cannot open shared object file: No such file or directory

Following your advice here; setting LD_LIBRARY_PATH for that individual project that depends on Rutie to the path where Ruby's dynamic library makes it work. I.e. I can run cargo test.

So now I'm going to experiment in how to make this behavior work with Rutie automatically without requiring user's of my crate to go through this same process.

danielpclark added a commit to danielpclark/rutie that referenced this issue Jun 4, 2019
danielpclark added a commit to danielpclark/rutie that referenced this issue Jun 16, 2019
Rust's C linker arguments don't work as they should.  See issue
rust-lang/cargo#4044 (comment)
for more details on this. Hopefully in the future C linker arguments and
library paths will improve.
@thomwiggers
Copy link
Contributor

I've run into this issue where cargo test --doc does not set LD_LIBRARY_PATH correctly, but my crate is building that shared library using cmake and it's located in the target/debug/build/.../out directory.

If you want to try this, it's this commit: open-quantum-safe/liboqs-rust@ef05887

cargo test --doc

fails;

LD_LIBRARY_PATH=/home/thom/.../oqs-rs/target/debug/build/oqs-sys-512f6110a29d60ba/out/build/lib/:/usr/local/lib cargo test --doc

works.

@epage epage added the S-triage Status: This issue is waiting on initial triage. label Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts A-linkage Area: linker issues, dylib, cdylib, shared libraries, so C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

8 participants