-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Inconsistent #[link(name = "")]
resolution on Windows
#62588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report! I"ve transferred this issue to the rust-lang/rust repository since this is more about the output filenames of rustc than anything to do with Cargo |
We can't change Producing I doubt there's anything we can do about this. |
I'm not sure I follow. When invoking the linker for If during compilation of the |
When you do As for a workaround, you can use #[cfg_attr(not(windows), link(name = "dylib"))]
#[cfg_attr(windows, link(name = "dylib.dll"))] |
I just checked with #[cfg_attr(all(target_os = "windows", target_env = "msvc"), link(name = "dylib.dll"))]
#[cfg_attr(not(all(target_os = "windows", target_env = "msvc")), link(name = "dylib"))]
extern "C" { ... } Although I wouldn't be surprised if other |
Once #60260 lands, there will be |
"Producing dylib.dll.lib is intentional to not conflict with dylib.lib for static libraries." This makes sense in a linux output environment. But windows generates dylib.lib and dylib.exp dylib.dll for a DLL. If a windows users builds a DLL there cannot be a .lib of the same name in that directory. So the naming convention is not consistent with Windows IMHO. |
This changes linking on Windows to work, while not breaking linking on other operating systems. Windows requires "cdylib.dll" whereas other OSes just require "dylib". For more information, see rust-lang/rust#62588
Background
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
from thedylib_test
crate, the#[link(name = "dylib")]
attribute behaves inconsistently. On Mac and Linux the attribute works. On Windows, it fails with anI believe this is because Rust on Windows produces a
dylib.dll
anddylib.dll.lib
(instead of adylib.lib
). When then resolving the library Rust apparently isn't aware that to resolvename="dylib"
it should not only look for the (dylib.lib
,dylib.dll
) pair, but instead also for the (dylib.dll.lib
,dylib.dll
) pair.Steps
cargo test
(on Windows)Possible Solution(s)
When given a
#[link(name = "dylib")]
, consider to look fordylib.dll.lib
on Windows.The current workaround is to specify
#[link(name = "dylib.dll")]
, but from a cross-platform perspective that feels inconsistent.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-pc-windows-msvc
The text was updated successfully, but these errors were encountered: