Skip to content

Missing "exe.linkLibrary(zglfw.artifact("glfw"));" in the build.zig example #31

@Logickin-Lambda

Description

@Logickin-Lambda

I have been puzzling on using this library for a good couple of hours because I kept on getting the errors about not linking the functions from the learn_opengl.exe.obj:

run
└─ run learn_opengl
   └─ zig build-exe learn_opengl Debug native 8 errors
error: lld-link: undefined symbol: glfwTerminate
    note: referenced by C:\Users\<users>\My Stuff\7_SoftwareDevelopment\zig\learn_opengl\src\main.zig:41
    note:               C:\Users\<users>\My Stuff\7_SoftwareDevelopment\zig\learn_opengl\.zig-cache\o\b2ec2d1bc7eaaef8f4ec186984fc35e5\learn_opengl.exe.obj:(main.main)
    note: referenced by C:\Users\<users>\My Stuff\7_SoftwareDevelopment\zig\learn_opengl\src\main.zig:41
    note:               C:\Users\<users>\My Stuff\7_SoftwareDevelopment\zig\learn_opengl\.zig-cache\o\b2ec2d1bc7eaaef8f4ec186984fc35e5\learn_opengl.exe.obj:(main.main)
error: lld-link: undefined symbol: glfwDestroyWindow
    note: referenced by C:\Users\<users>\My Stuff\7_SoftwareDevelopment\zig\learn_opengl\src\main.zig:48
    note:               C:\Users\<users>\My Stuff\7_SoftwareDevelopment\zig\learn_opengl\.zig-cache\o\b2ec2d1bc7eaaef8f4ec186984fc35e5\learn_opengl.exe.obj:(main.main)
error: lld-link: undefined symbol: glfwPollEvents
    note: referenced by C:\Users\<users>\My Stuff\7_SoftwareDevelopment\zig\learn_opengl\src\main.zig:53
    note:               C:\Users\<users>\My Stuff\7_SoftwareDevelopment\zig\learn_opengl\.zig-cache\o\b2ec2d1bc7eaaef8f4ec186984fc35e5\learn_opengl.exe.obj:(main.main)
.
.
.
and so on...

After having a look to the zig-gamedev samples you have suggested, it seems that the Getting Started section missed to link the library, which the following solution works:

const zglfw = b.dependency("zglfw", .{});
exe_mod.addImport("zglfw", zglfw.module("root"));
exe.linkLibrary(zglfw.artifact("glfw")); // <-- This is the missing line from the example

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