-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
A-rustflagsArea: rustflagsArea: rustflagsC-bugCategory: bugCategory: bugCommand-rustcS-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.Status: Needs more info, such as a reproduction or more background for a feature request.
Description
Problem
I am trying to stop build on linking phase so that I can provide required libraries later. When I execute rustc --emit=obj src/main.rs
it works fine, however with cargo rustc --emit=obj
it fails:
error: linking with `cc` failed: exit status: 1
With output of cargo --verbose -- --emit=obj
I see a command being executed with multiple emit
flags:
Running `.../rustc ... --emit=dep-info,link ... --emit=obj`
Steps
- create new project with
cargo init
- add this to
src/main.rs
:
unsafe extern "C" {
safe fn add(x: i32) -> i32;
}
fn main() {
println!("5 + 1 according to C: {}", add(5));
}
- Try to build with
cargo rustc -- --emit=obj
- It will fail with linking
- Try to build with the output of
cargo --verbose rustc -- --emit=obj
and remove cargo'semit
- It will work fine
Possible Solution(s)
Executing the same command with only one --emit=obj
works fine too, so possibly this issue is related to #14346.
Notes
Maybe there are another ways to stop build on linking phase, all I found is cargo rustc -- --emit=obj
(which doesn't work) and nightly cargo rustc -Zunstable-options -- -Zno-link
. If I am missing some other variants to do it on stable version, let me know please.
Version
cargo 1.88.0 (873a06493 2025-05-10)
release: 1.88.0
commit-hash: 873a0649350c486caf67be772828a4f36bb4734c
commit-date: 2025-05-10
host: x86_64-unknown-linux-gnu
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.12.1-DEV (sys:0.4.80+curl-8.12.1 vendored ssl:OpenSSL/3.4.1)
ssl: OpenSSL 3.4.1 11 Feb 2025
os: Fedora 41.0.0 (FortyOne) [64-bit]
MrSumato
Metadata
Metadata
Assignees
Labels
A-rustflagsArea: rustflagsArea: rustflagsC-bugCategory: bugCategory: bugCommand-rustcS-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.Status: Needs more info, such as a reproduction or more background for a feature request.