Upgrading build from SDL2 to SDL3

I’ve been working on a port of an old C Asteroids implementation to Zig, here. I’ve got the basic functionality working using SDL2. Before I start adding in extra functionality I wanted to get it running with SDL3. However, it falls over with the error, below, which has left me stumped. I don’t see what I’m doing wrong.

install
└─ install asteroids
   └─ zig build-exe asteroids Debug native 2 errors
src/main.zig:8:11: error: C import failed
const c = @cImport({
          ^~~~~~~~
/Users/iain/Workspace/C/asteroids/include/SDL3/SDL.h:34:10: error: 'SDL3/SDL_stdinc.h' file not found
#include <SDL3/SDL_stdinc.h>

I’ve checked, the SDL_stdinc.h header file is in the correct place. Here’s my current build.zig - I’ve just tweaked the SDL2’s to SDL3’s:

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "asteroids",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });

    exe.addLibraryPath(b.path("lib/SDL3"));
    exe.addIncludePath(b.path("include/SDL3"));
    exe.linkSystemLibrary("sdl3");

    b.installArtifact(exe);

    const run_exe = b.addRunArtifact(exe);

    const run_step = b.step("run", "Run the application");
    run_step.dependOn(&run_exe.step);
}

You probably need to change your build script to only use include as the include path, since SDL3/ is mentioned in the header files, otherwise the search will become include/SDL3/SDL3/SDL_foo.h.

2 Likes

Thanks, @kristoff. That was it. :grinning: I’ve now got the error messages I was expecting. :grin: