Closed
Description
Simple example:
// a.rs
#[crate_type="lib"];
#[link(name="aaa")] extern {}
// b.rs
#[crate_type="lib"];
extern mod a;
#[link(name="bbb")] extern {}
// c.rs
extern mod a; // not really relevant to this issue, does not change the behavior here
extern mod b;
fn main() {}
When compiled with rustc a.rs && rustc -L. b.rs && rustc -L. c.rs
, this obviously results in the linker error, but multiple trials reveal the random order of -laaa
and -lbbb
. If libbbb.a
depends on libaaa.a
then -laaa
should be put before -lbbb
; the current behavior is not acceptable for the purpose of FFI.
Some practical problem caused by this issue: If the external library (say, -lsqlite3
) depends on libc (-lc
) and the binding crate for that library is compiled as rlib, then the executable crate using those library and crate will randomly fail to link since we no longer implicitly link to -lc
(#12205) and thus the order of -lc
and -lsqlite3
is random. (We do still have -lc
since libstd depends on libc.)