Wrong linker order on Linux produces error. #62589
Labels
A-linkage
Area: linking into static, shared libraries and binaries
C-bug
Category: This is a bug.
O-linux
Operating system: Linux
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Background
Same background as #62588.
We have a Rust project (lets call it
dylib
) where we want to produce a shared library (.dll, .dylib, .so) for various platforms. As part of the build process we also want to verify the provided headers match the library.To do that we have a separate project
dylib_test
, where we extract C doc tests into individualgenerated_nnn.c
files, produce agenerated.rs
file that knows all C tests, and emits a#[test]
for each, which we then want to run withcargo test
.The
dylib
project should only emit acdylib
, and thedylib_test
should only link against thatcdylib
, to make sure the actual .dll, ... works.Problem
When linking against
dylib
, the#[link(name = "dylib")]
on Linux, Rust seems to place the linker arguments in the wrong order. If I executecargo test --release
on a regular Ubuntu 18.04, I get the following error message:Interestingly
-ldylib
(which containsget_version
) is already in that command. When I run the samecc
with an extra-ldylib
added to the end works. This is related to this Stackoverflow comment, that apparentlySteps
cargo test
(from Linux)Possible Solution(s)
?
Notes
Output of
cargo version
:cargo 1.37.0-nightly (4c1fa54d1 2019-06-24)
rustc 1.38.0-nightly (6e310f2ab 2019-07-07)
x86_64-unknown-linux-gnu
The text was updated successfully, but these errors were encountered: