Comments (4)
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.
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.
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.
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)
- Build failure when using LTO with static linking on MacOS
- -Csoft-float flag is unsound HOT 13
- [QNX7.1] `std::fs::tests::symlink_hard_link` broken on main HOT 3
- `TcpStream::set_nonblocking` docs mention non-existent methods HOT 3
- add unstable --no-minify flag to rustdoc HOT 5
- [rustdoc search] kind filters should not be allowed in type-based search
- driftsort implementation uses an out-of-range literal on 16-bit targets HOT 7
- ICE: `deadlock detected as we're unable to find a query cycle to break` HOT 2
- deadlock detected as we're unable to find a query cycle to break HOT 1
- Cargo fix error HOT 1
- s390x-unknown-linux-gnu: cfg!(target_feature = "backchain") is always true HOT 10
- ICE HOT 1
- c_char signedness doesn't match with Clang's default on various no-std and tier 3 targets HOT 1
- Trait bound requiring the same trait with different lifetimes results in a compile error
- rustc panicked when reference a moved variable in a closure
- taint on type error in `UniversalRegionsBuilder::compute_inputs_and_output`
- SIMD intrinsics are never inlined in debug
- generic type bound is somehow not effective when using type_alias_impl_trait
- lint-docs fails its tests in a cross-compiling environment
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust.