Skip to content

Commit 037bc65

Browse files
committed
Auto merge of #47052 - fschutt:master, r=estebank
Improved error messages for linking failure Partial fix for #46998 It's unnecessary to print the linker options if there is no linker installed in the first place. Currently, for libraries, the output is still printed, but that should be cleaned up in the future. If you don't have gcc or g++ installed, so that no linker is installed on the system, the output is now this: ``` $ ./rustc hello.rs error: linker `cc` not found | = note: No such file or directory (os error 2) error: aborting due to previous error ``` For libraries, the linker arguments are still printed, but they should be cleaned up in further commits.
2 parents ad30f54 + 7c13fa3 commit 037bc65

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

Diff for: src/Cargo.lock

+12-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/librustc_trans/back/link.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,25 @@ fn link_natively(sess: &Session,
708708
info!("linker stdout:\n{}", escape_string(&prog.stdout));
709709
},
710710
Err(e) => {
711-
sess.struct_err(&format!("could not exec the linker `{}`: {}", pname.display(), e))
712-
.note(&format!("{:?}", &cmd))
713-
.emit();
714-
if sess.target.target.options.is_like_msvc && e.kind() == io::ErrorKind::NotFound {
711+
let linker_not_found = e.kind() == io::ErrorKind::NotFound;
712+
713+
let mut linker_error = {
714+
if linker_not_found {
715+
sess.struct_err(&format!("linker `{}` not found", pname.display()))
716+
} else {
717+
sess.struct_err(&format!("could not exec the linker `{}`", pname.display()))
718+
}
719+
};
720+
721+
linker_error.note(&format!("{}", e));
722+
723+
if !linker_not_found {
724+
linker_error.note(&format!("{:?}", &cmd));
725+
}
726+
727+
linker_error.emit();
728+
729+
if sess.target.target.options.is_like_msvc && linker_not_found {
715730
sess.note_without_error("the msvc targets depend on the msvc linker \
716731
but `link.exe` was not found");
717732
sess.note_without_error("please ensure that VS 2013 or VS 2015 was installed \

Diff for: src/test/compile-fail/issue-10755.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
// compile-flags: -C linker=llllll -Z linker-flavor=ld
12-
// error-pattern: the linker `llllll`
12+
// error-pattern: linker `llllll` not found
1313

1414
fn main() {
1515
}

0 commit comments

Comments
 (0)