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

Discuss external linking and linking order #2

Open
petrochenkov opened this issue Nov 14, 2022 · 7 comments
Open

Discuss external linking and linking order #2

petrochenkov opened this issue Nov 14, 2022 · 7 comments

Comments

@petrochenkov
Copy link

petrochenkov commented Nov 14, 2022

So you get linking errors when using lapacke-sys without some other crate linking to liblapacke.

This was found when testing some linking order changes in rustc in rust-lang/rust#102832 (comment) (build failure - https://crater-reports.s3.amazonaws.com/pr-102832-1/try%230c94de7c1a8f4b82b92d562847c35f513f520c7a/gh/lopez86.rust-mlearn/log.txt).

The dependency on liblapacke should be declared using a #[link] attribute or a build script with cargo:rustc-link-lib.

@IvanUkhov
Copy link
Member

This is correct. The crate is not doing any linkage. Please refer to the architecture.

@petrochenkov
Copy link
Author

That architecture worked largely by luck so far.
You can see from the build failure log that the crate that uses symbols (lapacke-sys) doesn't declare a dependency on a library that defines those symbols (liblapacke.(so,a)). In general, rustc cannot build a correct linker command line in such situation.

@IvanUkhov
Copy link
Member

There might be some misunderstanding on my side. The linking happens when one chooses a source. In the case of the Netlib source, for instance, the corresponding instructions are given here:

https://github.com/blas-lapack-rs/netlib-src/blob/master/build.rs

Are you referring to this or something else?

@tari
Copy link

tari commented Nov 15, 2022

It looks like you've got the same problem as llvm-sys, where the set of linked libraries cannot be known until build-time. It seems like we'd need Cargo to support emitting an equivalent of links in the manifest from build scripts to make this work correctly.

@IvanUkhov
Copy link
Member

Yes, this is accurate. Thank you for looking into this!

@petrochenkov
Copy link
Author

I'll also look in more detail how this crate and llvm-sys setup things later this week.

The linking happens when one chooses a source.

I guess the main source of misunderstanding may come from the fact that it's not enough to link to the necessary library somewhere on the command line, it needs to be linked after it's used due to the order-dependent way in which unix-style linkers work (and the order is inferred from "crate -> crate" and "crate -> native lib" dependencies in rustc using topological sorting).

@IvanUkhov
Copy link
Member

Thank you. Let us add the following to the list:

  • blas-sys,
  • cblas-sys,
  • lapack-sys, and
  • lapacke-sys.

@IvanUkhov IvanUkhov changed the title This crate depends on native library liblapacke, but doesn't declare that dependency Discuss external linking and linking order Nov 15, 2022
@IvanUkhov IvanUkhov reopened this Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants