#Issues building release with SDL2

1 messages ยท Page 1 of 1 (latest)

gentle flume
#

Original discussion #game-dev message

Current status:

I've followed the recommendations, now I have:

    exe.addSystemIncludePath(.{ .path = "/usr/include" });
    exe.linkSystemLibrary("SDL2");
    exe.linkSystemLibrary("SDL2_ttf");
    exe.linkSystemLibrary("SDL2_image");
    exe.linkLibC();

but I"m still getting the same issue

error: error: unable to find Dynamic system library 'SDL2' using strategy 'paths_first'. searched paths: none
error: unable to find Dynamic system library 'SDL2_ttf' using strategy 'paths_first'. searched paths: none
error: unable to find Dynamic system library 'SDL2_image' using strategy 'paths_first'. searched paths: none
#

@wicked siren so what's the way to go when specifying the target?

wicked siren
#

usually the package manager if you need to build for different targets

gentle flume
#

I see. It's fine for SDL2, but not sure whether TTF and Image are available. I'll have a look ๐Ÿ™‚

slim ginkgo
#

However, SDL_ttf depends on freetype and harfbuzz.

gentle flume
#

I wish it was easier to compile/include C code in zig ๐Ÿฅฒ

slim ginkgo
#

Single header, no dependencies

gentle flume
#

I was trying to avoid mixing graphics libraries ๐Ÿ˜ž

slim ginkgo
#

Well, stb_truetype lets you generate a bitmap font using stbtt_BakeFontBitmap(). You can then upload it to an SDL_Surface

gentle flume
#

doesn't sound too bad then

slim ginkgo
gentle flume
#

thanks, that helps ๐Ÿ™‚

fluid stirrup
#

that way you dont need to fork anything and maintain it, you can just pin a version for the project and it's just fine

slim ginkgo
fluid stirrup
#

yep

#

lemme see if any of my projects that do this are on my github one sec

#

yeah no I dont think so sorry

#

here's a local one:

// build.zig.zon
.{
    .name = "nt",
    .version = "0.0.0",
    .dependencies = .{
        .raylib = .{
            .path = "raylib-zig",
        }
    },
    .paths = .{""},
}
// raylib-zig/build.zig.zon
.{
    .name = "raylib",
    .version = "5.0.0",
    .dependencies = .{
        .raylib = .{
            .url = "https://github.com/raysan5/raylib/archive/55e7d1aad13a1329d257ac948509a3a0ed2c20a9.tar.gz",
            .hash = "12204a0faac42bd832cbb5e615fdec08614a0417fc045ddb9ba0dc383ae8a845d3cc"
        }
    },
    .paths = .{""},
}
// raylib-zig/build.zig
const std = @import("std");

pub fn build(b: *std.Build) !void {

    const target = b.standardTargetOptions(.{});

    const optimize = b.standardOptimizeOption(.{});

    const rl_dep = b.dependency("raylib", .{});

    const rl = b.addStaticLibrary(.{
        .target = target,
        .optimize = optimize,
        .name = "raylib",
    });

    rl.addIncludePath(rl_dep.path("src/external/glfw/include"));
    rl.linkLibC();
    rl.addCSourceFiles(. {
        .dependency = rl_dep,
        .files = &.{
        // snipped for conciseness
        },
        .flags = &.{
            "-std=gnu99",
            "-D_GNU_SOURCE",
            "-DGL_SILENCE_DEPRECATION=199309L"
        }
    });


    rl.linkSystemLibrary("GL");
    rl.linkSystemLibrary("rt");
    rl.linkSystemLibrary("dl");
    rl.linkSystemLibrary("m");
    rl.linkSystemLibrary("X11");
    rl.defineCMacro("PLATFORM_DESKTOP", null);


    rl.installHeader(rl_dep.path("src/raylib.h").getPath(b), "raylib.h");
    _ = b.addModule("raylib", .{
        .source_file = .{.path = "c.zig"}
    });
    b.installArtifact(rl);
}
gentle flume
#

thanks @fluid stirrup ! I was trying to do this actually for SDL2_image, but didn't manage to get it working. I'll have a look at your example ๐Ÿ™‚

fluid stirrup
#

it should work, though SDL2/SDL2_image is more complicated to compile than raylib from what ive heard

gentle flume
#

hell

#

I wish Zig was clever enough to take that and just build it, instead of requiring a build.zig that does the same

wicked siren
#

there are already build.zigs for sdl

gentle flume
#

yeah, sdl2 is fine, I got a couple that work

wicked siren
#

sdl_image just looks like a handful of files and 1 header

fluid stirrup
gentle flume
#

I see that everyone out there is using stb though? Does anyone know what's the deal with it? Is it "better" than sdl_image?

fluid stirrup
wicked siren
#

also the single header thing make it very very easy to integrate into projects, no complicated build system(s) needed

gentle flume
#

yeah, that's a big headache saving

wicked siren
#

ye