raysan5 / raygui

A simple and easy-to-use immediate-mode gui library
zlib License
3.61k stars 303 forks source link

Does this work with the master branch of raylib? - Zig Compilation Error #417

Closed nat3Github closed 3 months ago

nat3Github commented 4 months ago

Does this work with the master branches of raylib? in zig I'm pulling from raylib and raygui master and get compile Errors inside an cImport.

raysan5 commented 4 months ago

@nat3Github yes, it should, I always work with raylib and raygui master branches

VisenDev commented 4 months ago

Zig compiles raygui.h using clang. Clang compiles c header files differently than it does normal c files. So you will get a compile error compiling raygui.h with zig in the normal way. See https://github.com/ziglang/zig/issues/19423

You need to do something like this

build.zig

    const raylib_dep = @import("raylib");

    const ray = try raylib_dep.addRaylib(b, target, optimize, .{ .raygui = true });
    exe.linkLibrary(ray);

build.zig.zon

        .raylib = .{
            .url = "https://github.com/raysan5/raylib/archive/f5d2f8d.tar.gz",
            .hash = "12201c7e120800ecf29429560eefb2f2df58a176ee1f949e9e275944df048e0c22b2",
        },
        .raygui = .{
            .url = "https://github.com/raysan5/raygui/archive/refs/heads/master.tar.gz",
            .hash = "1220c62ef63613b8cb2893748d6baa344cd2d994328fbf3fe7559bec00a144c991e5",
        },

import raygui like this

main.zig

const ray = @cImport({
    @cInclude("raylib.h");
});

const raygui = @cImport({
    @cInclude("raygui.h");
});