Skip to content

Link directly against DLLs for gnu toolchains to eliminate the need for import libraries #478

Closed
@GabrielMajeri

Description

@GabrielMajeri

As far as I can understand, the winapi-i386/x86_64-pc-windows-gnu crates exist because the Rust MinGW toolchain does not include the import libraries for these DLLs, right? Therefore there should no way to link against them.

Except there is, and it requires no import libraries. ld is a really cool linker - it's able to link against DLLs without requiring an import .lib file.

Here is an example. Let's say I am trying to build this using the nightly-gnu toolchain on Windows:

// Some random function.
#[link(name = "audioeng")]
extern "system" { fn AERT_Allocate(); }

fn main() { unsafe { AERT_Allocate(); } }

If I compile this as-is, I get a link error with the ld linker.

 = note: ld: cannot find -laudioeng

But AudioEng is a DLL, and it exists in my C:\Windows\System32\ folder. If I ask ld to also search in that folder, by using a build.rs file:

fn main() {
	println!("cargo:rustc-link-search=native=C:\\Windows\\System32\\");
}

I can now build it just fine:

     Finished dev [unoptimized + debuginfo] target(s) in 0.59 secs
     Running `target\debug\test.exe`

Would it be possible for winapi-rs to drop those auxilliary crates and just add the C:\\Windows\\System32\ folder to the native search dirs for MinGW? It would greatly simplify development.

Note: the folders, on a 64-bit native Windows, are \System32 for 64-bit DLLs and \SysWOW64 for 32-bit DLLs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions