#undefined symbols when using zgui + zglfw + vulkan-zig

1 messages · Page 1 of 1 (latest)

main knot
#

I'm trying to integrate zgui into my renderer, which uses zglfw and vulkan-zig.

However, I'm getting the following errors:

error: undefined symbol: _ImGui_ImplGlfw_InitForVulkan
    note: referenced by .zig-cache/o/0fded4198a5455cf859645677c411b12/renderer_zcu.o:_backend_glfw.initVulkan
error: undefined symbol: _ImGui_ImplVulkan_CreateFontsTexture
    note: referenced by .zig-cache/o/0fded4198a5455cf859645677c411b12/renderer_zcu.o:_backend_vulkan.init
error: undefined symbol: _ImGui_ImplVulkan_Init
    note: referenced by .zig-cache/o/0fded4198a5455cf859645677c411b12/renderer_zcu.o:_backend_vulkan.init
error: the following command failed with 3 compilation errors:

The missing functions are defined here:
https://github.com/zig-gamedev/zgui/blob/7bc9461997c402c1be9bc716388399404df1686e/src/backend_glfw.zig#L42

I expect them to be statically linked.
I'm not sure why they're not being resolved...

My build.zig looks like this:

const zgui = b.dependency(
        "zgui",
        .{
            .target = target,
            .optimize = optimize,
            .backend = .glfw_vulkan,
        },
    );
    const zgui_module = zgui.module("root");
    const imgui = zgui.artifact("imgui");
    imgui.addIncludePath(vulkan_headers.path("include"));
    renderer_module.addImport("zgui", zgui_module);
    renderer_module.linkLibrary(imgui);
#

Unless I'm reading it wrong, I think the functions are included in the libimgui.a (==output of zgui_module.artifact("imgui"), against which renderer_module is linked)

% nm libimgui.a | grep InitFor
00000000000018c8 T __Z27ImGui_ImplGlfw_InitForOtherP10GLFWwindowb
00000000000014cc T __Z28ImGui_ImplGlfw_InitForOpenGLP10GLFWwindowb
0000000000001894 T __Z28ImGui_ImplGlfw_InitForVulkanP10GLFWwindowb
#

Ah, the names are mangled, so that's why the zig-side extern function isn't getting resolved to the c++ one.

#

Adding extern c to the function declaration helped:

extern "C" IMGUI_IMPL_API bool     ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks);
nm ./libimgui.a | grep InitFor
0000000000001894 T _ImGui_ImplGlfw_InitForVulkan