Skip to content

Linking a dylib/DLL is broken on windows #25891

Closed
@alexchandel

Description

@alexchandel

Attempting to link a crate as a "dylib" on windows, specifically the nightly i686-pc-windows-gnu, to produce a DLL results in a linker error if that crate uses array subscripting. For example, compiling with no options,

#![crate_type = "dylib"]
pub unsafe extern "system" fn foo() -> f64 {
    let x: [f64; 4] = [0.0, 1.0, 2.0, 3.0];
    x[2]
}

results in a linker error,

error: linking with `gcc` failed: exit code: 1
note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-Wl,--large-address-aware" "-shared-libgcc" "-L" "C:\tools\rust32\bin\rustlib\i686-pc-windows-gnu\lib" "alg.o" "-o" "alg.dll" "alg.metadata.o" "C:\tools\rust32\bin\rustlib\i686-pc-windows-gnu\lib\libstd-11582ce5.rlib" "C:\tools\rust32\bin\rustlib\i686-pc-windows-gnu\lib\libcollections-11582ce5.rlib" "C:\tools\rust32\bin\rustlib\i686-pc-windows-gnu\lib\librustc_unicode-11582ce5.rlib" "C:\tools\rust32\bin\rustlib\i686-pc-windows-gnu\lib\librand-11582ce5.rlib" "C:\tools\rust32\bin\rustlib\i686-pc-windows-gnu\lib\liballoc-11582ce5.rlib" "C:\tools\rust32\bin\rustlib\i686-pc-windows-gnu\lib\liblibc-11582ce5.rlib" "C:\tools\rust32\bin\rustlib\i686-pc-windows-gnu\lib\libcore-11582ce5.rlib" "-L" "C:\tools\rust32\bin\rustlib\i686-pc-windows-gnu\lib" "-L" "c:\Users\alex\Projects\XALG_Counter\.rust\bin\i686-pc-windows-gnu" "-L" "c:\Users\alex\Projects\XALG_Counter\bin\i686-pc-windows-gnu" "-Wl,-Bstatic" "-Wl,-Bdynamic" "-l" "ws2_32" "-l" "userenv" "-l" "advapi32" "-shared" "-l" "compiler-rt"
note: C:\tools\rust32\bin\rustlib\i686-pc-windows-gnu\lib\libcore-11582ce5.rlib(core-11582ce5.o):(.text+0x7fe4): undefined reference to `rust_begin_unwind'
C:\tools\rust32\bin\rustlib\i686-pc-windows-gnu\lib\libcore-11582ce5.rlib(core-11582ce5.o):(.eh_frame+0x9a67): undefined reference to `rust_eh_personality'
ld: C:\tools\rust32\bin\rustlib\i686-pc-windows-gnu\lib\libcore-11582ce5.rlib(core-11582ce5.o): bad reloc address 0x9a67 in section `.eh_frame'

error: aborting due to previous error

Passing the -C linker=C:/tools/rust32/bin/rustlib/i686-pc-windows-gnu/bin/gcc.exe, doesn't help, nor does compiling for x86_64, nor with the flag -C linker="C:/tools/rust/bin/rustlib/x86_64-pc-windows-gnu/bin/gcc.exe".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions