Skip to content

Error 126 while loading DLL compiled by Rust (as a cdylib) on Windows #69207

@silverweed

Description

@silverweed

Note: looks very similar to #33842, but I'm opening a new issue since that is closed and old.

Basically I'm having the same issue here. This is my project which has 3 crates: one static lib, one dynamic lib (cdylib) and an executable.
The dynamic lib (ecs_game) depends on the static lib (ecs_engine) and gets compiled into a single DLL. The executable (ecs_runner) then loads the DLL dynamically (I'm using the libloading crate for that).
Here is what happens:

  • on Linux/Mac, the lib gets loaded just fine
  • on an old (pre-anniversary update) Windows, it gets loaded just fine
  • on newer Windows installations, it fails with error 126.

I also tried to create a small C program that uses LoadLibraryA directly to load the library and it gives the same exact error.
Am I doing something wrong here?

(this is the C loader:)

#include <windows.h>
#include <stdio.h>

int main() {
	HMODULE lib = LoadLibraryA("ecsde/target/release/ecs_game.dll");
	if (lib) {
		printf("Hurray!\n");
	} else {
		DWORD last_err = GetLastError();
		printf("Failed to load. Last err = %d\n", last_err);
	}
}

Note that if I link the DLL at link-time, it works fine. It's just dynamic loading that gives problems.

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