Skip to content
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

rustc 1.82.0 doesn't add LIBPATH when invoking link.exe #132016

Open
nandin-borjigin opened this issue Oct 22, 2024 · 4 comments
Open

rustc 1.82.0 doesn't add LIBPATH when invoking link.exe #132016

nandin-borjigin opened this issue Oct 22, 2024 · 4 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nandin-borjigin
Copy link

nandin-borjigin commented Oct 22, 2024

Rust-to-rust dynamic linking (through import library) on Windows fails with toolchain version 1.82.0.

The build log shows that 1.82.0 is not adding any /LIBPATH arguments when invoking link.exe.

I tried this code: nandin-borjigin/rustc-1.82.0-repro

Image

I expected to see this happen: Successful build

Instead, this happened: LINK : fatal error LNK1181: cannot open input file 'mylib.dll.lib'

Image

Meta

rustc --version --verbose:

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-pc-windows-msvc
release: 1.82.0
LLVM version: 19.1.1
Backtrace

Possibly related

@nandin-borjigin nandin-borjigin added the C-bug Category: This is a bug. label Oct 22, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 22, 2024
@ChrisDenton
Copy link
Member

cc @petrochenkov, I believe there were some changes to linking with msvc?

@nandin-borjigin
Copy link
Author

Adding this build script helps, but I think this should only be considered a workaround and rustc should emit library search path by default.

    println!("cargo:rustc-link-search=native={}/deps", out_dir.display());

@jieyouxu jieyouxu added A-linkage Area: linking into static, shared libraries and binaries O-windows Operating system: Windows O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed O-windows Operating system: Windows labels Oct 22, 2024
@bjorn3
Copy link
Member

bjorn3 commented Oct 22, 2024

I don't think this was supposed to work out of the box. Either you should make my_lib a cdylib (requiring you to build the cdylib from within the build script rather than specifying it as dependency, at least until artifact dependencies are stable) and link it like a C library (which includes adding it to the linker search path from a build script) or you should link it like a regular rust library and avoid #[link(name = "my_lib.dll")] extern "C" {}.

@petrochenkov
Copy link
Contributor

This is likely from #128370.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants