Git Product home page Git Product logo

Comments (4)

ehuss avatar ehuss commented on September 4, 2024

Can you please share the exact output you are receiving in the case where it doesn't seem to work? I am unable to reproduce given your example.

from rust.

ehuss avatar ehuss commented on September 4, 2024

Oh, correction, I am able to reproduce:

  = note: /usr/bin/ld: /tmp/cargo-build-linking-bug/linking-with-lib-doesnt/target/debug/deps/buildrs_linking_bug-87372c54d74efe55.6x51e5ear2x9hplszhwkzwe3l.rcgu.o: in function `buildrs_linking_bug::main':
          /tmp/cargo-build-linking-bug/linking-with-lib-doesnt/src/main.rs:6: undefined reference to `my_custom_fn'
          collect2: error: ld returned 1 exit status

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)

warning: `buildrs-linking-bug` (bin "buildrs-linking-bug") generated 1 warning
error: could not compile `buildrs-linking-bug` (bin "buildrs-linking-bug") due to 1 previous error; 1 warning emitted

This behavior is documented here: https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib

Does the explanation there help understand why it works that way?

from rust.

kusnezoff-alexander avatar kusnezoff-alexander commented on September 4, 2024

Ah yes I see, it's all documented there. Thank you.

Still I find the error message to be misleading, since it tells to specify the library via cargo:rustc-link-lib which is already done. I think it would be a good thing to display another error-message in the case of both a library- and binary-target existing for the package. Something like:

 = note: /usr/bin/ld: /tmp/cargo-build-linking-bug/linking-with-lib-doesnt/target/debug/deps/buildrs_linking_bug-87372c54d74efe55.6x51e5ear2x9hplszhwkzwe3l.rcgu.o: in function `buildrs_linking_bug::main':
          /tmp/cargo-build-linking-bug/linking-with-lib-doesnt/src/main.rs:6: undefined reference to `my_custom_fn'
          collect2: error: ld returned 1 exit status

  = note: Your package has both a binary and library target. Since  the library has access to the symbols from the given lib, the binary should access them through the library target’s public API. (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)

from rust.

ehuss avatar ehuss commented on September 4, 2024

Unfortunately I don't know of a feasible way to do that right now. rustc doesn't know anything about cargo, and it is the one generating the message. Cargo doesn't know anything about linking, and wouldn't be able to know what is happening.

Transferred to rust-lang/rust since this message is generated by rustc. I don't know if the wording could possibly be tweaked to avoid this confusion.

from rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.