-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Linker: ld: library not found #141756
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
Comments
Does it work on the latest nightly? You can try using cargo-bisect-rustc to narrow down what the problem could be. But your setup seems a bit strange, you're adding it as a cargo dependency and then also linking it in via FFI? The problem can probably be resolved by adding the directory where you store the library to the linker library search path with a build script. |
yeah this is broken this We add it in via cargo as a dep to make sure its being build for the project, which dumps the lib into the release folder, where the linker can pick it up to link to it. As we don't use this a normal rust library in the test here, we specifically want to test it as an externally linked FFI. |
Adding a cdylib or staticlib as cargo dependency to a crate isn't guaranteed to work. You have to run cargo from for example a build script instead.
Rustc is only guaranteed to look into the explicitly passed linker search paths which you can set using a build script: https://doc.rust-lang.org/stable/cargo/reference/build-scripts.html#rustc-link-search |
Yes, but by building it as part of the project, it builds it to the project dep folder My question is what changed between Running |
Run cargo-bisect-rustc to narrow down the commit to see what changed |
This was probably #128370 which stopped passing the crate search path to the linker as it is only supposed to be used for finding rust dependencies, not for arbitrary libraries exporting a C ABI (like cdylib and staticlib crates). |
|
I see #128370 in the list here |
As I suspected. So basically it worked by accident before that PR and now you have to explicitly add the right directory to the linker search path. |
Awesome, let me get to fixing that, thanks for the help is figuring this out. |
I am not sure if this is a bug or not, but after upgrading nightly versions,I keep getting this error:
ld: library 'ffi_lib' not found
when trying to build a Rust Cucumber test containing a FFI library. Any help in either getting this resolved or fixed would be greatly appreciated.So we have a cucumber test crate that tests an FFI crate.
The project structure looks as follows:
We include the FFI library in the cargo.toml file with :
Then its linked into the code via:
The
cargo.toml
of ffi_lib contains this:Now this code works on Rust
nightly-2024-08-03
and earlier, but as soon as you increase the version tonightly-2024-08-04
or later it breaks with:I am struggling to find what rustc versions are used by these nightly version or docs about what could have changed. For what its worth this was done on a Mac M1, but fails on Unix CI as well with the same issue, so I doubt its a OSX only issue.
I can also see the
ffi_lib
library is built, and all its files are in the target folder.Also
Running
cargo +nightly-2025-05-01 test --all-features --release -v
I can see that rustc is adding in the
-lffi_lib
flag to include the library.The text was updated successfully, but these errors were encountered: