Add raylib from custom folder

I am trying to link with raylib in ./raylib-6.0 folder (relative to root) and using the recommened release notes 0.16 translate-c
I have:

  • zig version → 0.16.0
  • project is fresh zig init
  • ./raylib-6.0/lib and ./raylib-6.0/include folders in the root directory
  • modified build.zig from zig init to match the release notes. Here is the modified section (with comments removed)
const translate_c = b.addTranslateC(.{
        .root_source_file = b.path("src/c.h"),
        .target = target,
        .optimize = optimize,
    });
    const translate_c_mod = translate_c.createModule();
    translate_c_mod.addLibraryPath(b.path("./raylib-6.0/lib"));
    translate_c_mod.addIncludePath(b.path("./raylib-6.0/include"));
    
    translate_c.linkSystemLibrary("raylib", .{});

    translate_c.linkSystemLibrary("raylib", .{});

    const exe = b.addExecutable(.{
        .name = "raylib_demo",
        .root_module = b.createModule(.{
           
            .root_source_file = b.path("src/main.zig"),
            .target = target,
            .optimize = optimize,
            .imports = &.{
                .{ .name = "raylib_demo", .module = mod },
                .{
                    .name = "c",
                    .module = translate_c_mod,
                },
            },
        }),
    });

I get the error unable to find dynamic system library 'raylib' using strategy 'paths_first'. searched paths and list of system folders that doesn’t include ./raylib-6.0/*.

I also tried b.addSearchPrefix since I don’t know what it does and the name suggests that zig build uses it to search for libraries (like --search-prefix and option too didn’t work)

Any suggestion for a solution to modify the list zig searches? I know I can just put raylib in /usr/local/lib but it bothers me that I don’t understand why it is not working

I think you should add the linkSystemLibrary to translate_c_mod, not translate_c.

Thanks! this solved the problem with the libraries (and now it somewhat makes sense)

I ran into another problem the system didn’t find includes and have to .addInlcudePath with translate_c so in total the modifications are translate_c_mode.linkSystemLibrary("raylib",.{}) and translate_c.addInlcudePath(b.path("raylib-6.0/include")) (weird that includepath with translateC but librarypath with module)

1 Like

TranslateC does not need to link with libraries, it just needs to know the definitions. But a module needs to know where the symbols are for those definitions. Thats why. It takes some time to get used to zig’s build system but once it clicks, it is pretty straight forward.

1 Like