Open
Description
The main goal of +crt-static
(at least on non-Windows targets) is to produce self-contained statically linked executables.
With this goal in mind rustc
switches linking of 1) Rust crates and 2) libc to static if possible. (The libc
part is done in the libraries through lazy cfg
s though.)
However, for native dependencies with unspecified kind rustc
will still prefer the dynamic version of the library if both are available.
Unfortunately, doing this is not entirely trivial because -Bstatic -lmylib
won't just prefer the static version (e.g. libmylib.a
), it will require it.
So we need to check for the existence of libmylib.a
first (in which directories exactly?) and then pass -l:libmylib.a
instead of -lmylib
if it exists.