Skip to content

Dynamic Linking does not work on Windows MinGW Target #21103

Description

@AeroSW

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

Setup

  1. Download raylib release version 5 for MinGW
  2. Pull its contents into a directory local with the project, ./raylib
  3. Update build target to be MinGW (Windows + GNU = MinGW):
    const target = b.standardTargetOptions(.{
        .default_target = .{
            .os_tag = .windows,
            .cpu_arch = .x86_64,
            .abi = .gnu
        }
    });
  1. Ensure you have your dependencies for raylib linked
    • Note the link modes below state static, but the result is the same with dynamic as well.
    exe.linkLibC();
    exe.addIncludePath(b.path("./raylib/include"));
    exe.addLibraryPath(b.path("./raylib/lib"));
    exe.linkSystemLibrary2("uuid", .{
        .preferred_link_mode = .static,
        .needed = true
    });
    exe.linkSystemLibrary2("gdi32", .{
        .preferred_link_mode = .static,
        .needed = true
    });
    exe.linkSystemLibrary2("winmm", .{
        .preferred_link_mode = .static,
        .needed = true
    });
  1. Attempt to have build.zig link raylib dynamically
    exe.linkSystemLibrary2("raylib", .{
        .preferred_link_mode = .dynamic,
        .needed = true,
    });
  1. Attempt to run zig build --verbose install. It should produce the following error:
error: error(link): DLL import library for -lraylib not found
error: DllImportLibraryNotFound

The attempting to search for the DLL seems to be tied to a raylib.lib file being present despite MinGW configuration using libraylib.a libraries. This might have been an oversight when parsing configurations to search for DLLs.

Expected Behavior

Expected behavior should be for Zig to be able to accurately find the DLL while using MinGW and not MSVC environment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions