Skip to content

Output filename collision with dylib on windows release mode #8794

@khyperia

Description

@khyperia

This repro case looks really convoluted, my apologies, but, it has a (sort of sane) full use case. Linking #6313 because it's referenced in the output log. I'm not sure if this is a rustc bug or a cargo bug, but it feels like a cargo bug, so I'm filing it here - feel free to tell me to file it on the rust repo.

Here's contents of the whole project for the repro:

./Cargo.toml

[workspace]
members = [
    "thedylib",
    "dylibtest"
]

./thedylib/Cargo.toml

[package]
name = "thedylib"
version = "0.1.0"
authors = ["khyperia <github@khyperia.com>"]
edition = "2018"

[lib]
crate-type = ["dylib"]

[dependencies]

./thedylib/src/lib.rs

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}

./dylibtest/Cargo.toml

[package]
name = "dylibtest"
version = "0.1.0"
authors = ["khyperia <github@khyperia.com>"]
edition = "2018"

[build-dependencies]
thedylib = { path = "../thedylib" }

./dylibtest/build.rs

fn main(){}

./dylibtest/src/main.rs

fn main() {
    println!("Hello, world!");
}

On windows:

cargo build succeeds without error. (what?? why does debug succeed but release fail??)

cargo build --release fails:

Click to expand large amount of output
warning: output filename collision.
The lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)` has the same output filename as the lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)`.
Colliding filename is: D:\src\dylibtest\target\release\deps\thedylib.dll
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
warning: output filename collision.
The lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)` has the same output filename as the lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)`.
Colliding filename is: D:\src\dylibtest\target\release\thedylib.dll
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
warning: output filename collision.
The lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)` has the same output filename as the lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)`.
Colliding filename is: D:\src\dylibtest\target\release\deps\thedylib.dll.lib
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
warning: output filename collision.
The lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)` has the same output filename as the lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)`.
Colliding filename is: D:\src\dylibtest\target\release\thedylib.dll.lib
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
warning: output filename collision.
The lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)` has the same output filename as the lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)`.
Colliding filename is: D:\src\dylibtest\target\release\deps\thedylib.dll.exp
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
warning: output filename collision.
The lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)` has the same output filename as the lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)`.
Colliding filename is: D:\src\dylibtest\target\release\thedylib.dll.exp
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
warning: output filename collision.
The lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)` has the same output filename as the lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)`.
Colliding filename is: D:\src\dylibtest\target\release\deps\thedylib.pdb
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
warning: output filename collision.
The lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)` has the same output filename as the lib target `thedylib` in package `thedylib v0.1.0 (D:\src\dylibtest\thedylib)`.
Colliding filename is: D:\src\dylibtest\target\release\thedylib.pdb
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
   Compiling thedylib v0.1.0 (D:\src\dylibtest\thedylib)
error: linking with `link.exe` failed: exit code: 1104
  |
  = note: "D:\\Apps\\VS\\VC\\Tools\\MSVC\\14.27.29110\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\khype\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "D:\\src\\dylibtest\\target\\release\\deps\\thedylib.thedylib.8ocyyr2v-cgu.0.rcgu.o" "/OUT:D:\\src\\dylibtest\\target\\release\\deps\\thedylib.dll" "/DEF:C:\\Users\\khype\\AppData\\Local\\Temp\\rustcJd4Hni\\lib.def" "D:\\src\\dylibtest\\target\\release\\deps\\thedylib.2jin648boaw7s1nu.rcgu.o" "/OPT:REF,ICF" "/DLL" "/IMPLIB:D:\\src\\dylibtest\\target\\release\\deps\\thedylib.dll.lib" "/DEBUG" "/NATVIS:C:\\Users\\khype\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\khype\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\khype\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\khype\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis" "/LIBPATH:D:\\src\\dylibtest\\target\\release\\deps" "/LIBPATH:C:\\Users\\khype\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/LIBPATH:C:\\Users\\khype\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "std-1feb4ba9912f83e4.dll.lib" "C:\\Users\\khype\\AppData\\Local\\Temp\\rustcJd4Hni\\libcompiler_builtins-0f66c8d6b2ebbbc4.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
  = note: LINK : fatal error LNK1104: cannot open file 'D:\src\dylibtest\target\release\deps\thedylib.dll'
          

error: aborting due to previous error

error: could not compile `thedylib`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed

I'm not too sure what's going on here, but it's really weird. I believe both debug and release work on linux, but I'm not 100% sure.

Output of cargo version:

cargo 1.47.0 (f3c7e066a 2020-08-28)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layoutArea: target output directory layout, naming, and organizationC-bugCategory: bugO-windowsOS: WindowsS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions