ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.17k stars 2.5k forks source link

Trying to link glfw causes DLL import library for -lglfw3 not found (windows 11) #17035

Closed Triangle345 closed 1 year ago

Triangle345 commented 1 year ago

Zig Version

0.12.0-dev.167+dd6a9caea

Steps to Reproduce and Observed Behavior

I'm going to list the steps that I took to get to where I am. There are probably less cumbersome ways, but since I'm solely dealing with raylib this is my process: 1.) download raylib 2.) zig build to produce raylib.lib inside zig-out/lib 3.) download glfw windows binaries from glfw website ( i used mingw64) 4.) run the below commands

As you can see below, it fails to even find the glfw3 library even though I have the correct lib path set up with the correct shared lib.

This seems like a bug but since I'm fairly new to zig, it could be user error on my part :(.

~/Downloads\\zig-windows-x86_64-0.12.0-dev.167+dd6a9caea\zig.exe build-exe .\hello.zig -lraylib -Lzig-out/lib  -Izig-out/include -lc -lglfw3
LLD Link... error(link): DLL import library for -lglfw3 not found
error: DllImportLibraryNotFound
PS C:\Users\peterpan\raylib> ls .\zig-out\lib

    Directory: C:\Users\peterpan\raylib\zig-out\lib

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         8/31/2023   6:47 PM         234496 glfw3.dll
-a----         8/31/2023   6:47 PM         290550 libglfw3.a
-a----         8/31/2023   6:47 PM          83380 libglfw3dll.a
-a----         8/29/2023   2:12 PM       10256218 raylib.lib

Here is my hello.zig sample file:

PS C:\Users\peterpan\raylib> gc .\hello.zig    
// build with `zig build-exe cimport.zig -lc -lraylib`
const ray = @cImport({
    @cInclude("raylib.h");
});

pub fn main() void {
    const screenWidth = 800;
    const screenHeight = 450;

    ray.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
    defer ray.CloseWindow();

    // ray.SetTargetFPS(60);

    // while (!ray.WindowShouldClose()) {
    //     ray.BeginDrawing();
    //     defer ray.EndDrawing();

    //     ray.ClearBackground(ray.RAYWHITE);
    //     ray.DrawText("Hello, World!", 190, 200, 20, ray.LIGHTGRAY);
    // }
}

Expected Behavior

I expected my hello.zig program to compile and/or give errors not related to glfw

Beyley commented 1 year ago

i think you are missing glfw3.lib

Triangle345 commented 1 year ago

i think you are missing glfw3.lib

Thank you for the advice! I simply included the glfw3.lib from the vs2022 binary and was able to link. Obviously a few more errors showed up but I was able to remedy them like so:

~/Downloads\\zig-windows-x86_64-0.12.0-dev.167+dd6a9caea\zig.exe build-exe .\hello.zig -lraylib -Lzig-out/lib  -Izig-out/include -Izig-out/include/GLFW -lc -lglfw3 -lgdi32 -lwinmm