From 097b6d3bafb1d61bfe8fd3f5e9d9acfd9ee2c702 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Wed, 12 Oct 2022 22:52:31 -0400 Subject: Add suggestion to the "missing native library" error If we fail to locate a native library that we are linking with, it could be the case the user entered a complete file name like `foo.lib` or `libfoo.a` when we expect them to simply provide `foo`. In this situation, we now detect that case and suggest the user only provide the library name itself. --- src/test/ui/native-library-link-flags/suggest-libname-only-1.rs | 9 +++++++++ .../ui/native-library-link-flags/suggest-libname-only-1.stderr | 6 ++++++ src/test/ui/native-library-link-flags/suggest-libname-only-2.rs | 9 +++++++++ .../ui/native-library-link-flags/suggest-libname-only-2.stderr | 6 ++++++ 4 files changed, 30 insertions(+) create mode 100644 src/test/ui/native-library-link-flags/suggest-libname-only-1.rs create mode 100644 src/test/ui/native-library-link-flags/suggest-libname-only-1.stderr create mode 100644 src/test/ui/native-library-link-flags/suggest-libname-only-2.rs create mode 100644 src/test/ui/native-library-link-flags/suggest-libname-only-2.stderr (limited to 'src') diff --git a/src/test/ui/native-library-link-flags/suggest-libname-only-1.rs b/src/test/ui/native-library-link-flags/suggest-libname-only-1.rs new file mode 100644 index 00000000000..abf988a7c1e --- /dev/null +++ b/src/test/ui/native-library-link-flags/suggest-libname-only-1.rs @@ -0,0 +1,9 @@ +// build-fail +// compile-flags: --crate-type rlib +// error-pattern: could not find native static library `libfoo.a` +// error-pattern: only provide the library name `foo`, not the full filename + +#[link(name = "libfoo.a", kind = "static")] +extern { } + +pub fn main() { } diff --git a/src/test/ui/native-library-link-flags/suggest-libname-only-1.stderr b/src/test/ui/native-library-link-flags/suggest-libname-only-1.stderr new file mode 100644 index 00000000000..64d0a9077ed --- /dev/null +++ b/src/test/ui/native-library-link-flags/suggest-libname-only-1.stderr @@ -0,0 +1,6 @@ +error: could not find native static library `libfoo.a`, perhaps an -L flag is missing? + | + = help: only provide the library name `foo`, not the full filename + +error: aborting due to previous error + diff --git a/src/test/ui/native-library-link-flags/suggest-libname-only-2.rs b/src/test/ui/native-library-link-flags/suggest-libname-only-2.rs new file mode 100644 index 00000000000..dfa70e56db7 --- /dev/null +++ b/src/test/ui/native-library-link-flags/suggest-libname-only-2.rs @@ -0,0 +1,9 @@ +// build-fail +// compile-flags: --crate-type rlib +// error-pattern: could not find native static library `bar.lib` +// error-pattern: only provide the library name `bar`, not the full filename + +#[link(name = "bar.lib", kind = "static")] +extern { } + +pub fn main() { } diff --git a/src/test/ui/native-library-link-flags/suggest-libname-only-2.stderr b/src/test/ui/native-library-link-flags/suggest-libname-only-2.stderr new file mode 100644 index 00000000000..e166af9ed8f --- /dev/null +++ b/src/test/ui/native-library-link-flags/suggest-libname-only-2.stderr @@ -0,0 +1,6 @@ +error: could not find native static library `bar.lib`, perhaps an -L flag is missing? + | + = help: only provide the library name `bar`, not the full filename + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5