Error: lld-link: undefined symbol: _setjmp

I was following this tutorial on how to use the SDL_ttf library when I got this error:

error: lld-link: undefined symbol: _setjmp
    note: referenced by ../external/freetype/src/sfnt/ttcmap.c:3843
    note:               libSDL2_ttf.a(libSDL2_ttf_la-sfnt.o):(tt_face_build_cmaps.isra.0)
    note: referenced by ../external/freetype/src/smooth/ftgrays.c:1929
    note:               libSDL2_ttf.a(libSDL2_ttf_la-smooth.o):(gray_convert_glyph_inner)

My build.zig looks like this:

const std = @import("std");

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

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

    exe.addIncludePath(b.path("dep/SDL2-2.30.5/include/"));
    exe.addIncludePath(b.path("dep/SDL2_image-2.8.2/x86_64-w64-mingw32/include/SDL2/"));
    exe.addIncludePath(b.path("dep/SDL2_ttf-2.22.0/x86_64-w64-mingw32/include/SDL2/"));

    exe.addLibraryPath(b.path("dep/SDL2-2.30.5/lib/x64/"));
    exe.addLibraryPath(b.path("dep/SDL2_image-2.8.2/x86_64-w64-mingw32/lib/"));
    exe.addLibraryPath(b.path("dep/SDL2_ttf-2.22.0/x86_64-w64-mingw32/lib/"));

    exe.linkSystemLibrary("c");
    exe.linkSystemLibrary("SDL2");
    exe.linkSystemLibrary("shlwapi");
    exe.linkSystemLibrary("gdi32");
    exe.linkSystemLibrary("winmm");
    exe.linkSystemLibrary("Rpcrt4");
    exe.linkSystemLibrary("SDl2main");
    exe.linkSystemLibrary("SDL2_image");
    exe.linkSystemLibrary("SDL2_ttf");

    b.installArtifact(exe);

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

    
    const exe_unit_tests = b.addTest(.{
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });

    const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);

    // Similar to creating the run step earlier, this exposes a `test` step to
    // the `zig build --help` menu, providing a way for the user to request
    // running the unit tests.
    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&run_exe_unit_tests.step);

}

Do I need to link an another library or something?

Edit: Ignore the setup for exe_unit_tests because I don’t need it for now.

_setjmp is part of libc.

Try to remove exe.linkSystemLibrary("c"); and add:

exe.linkLibC();
exe_unit_tests.linkLibC();

I think I had a similar issue with a different library earlier this year.
I think the problem was some kind of incompatibility between different compilers.
Compiling the library with Zig’s C/C++ compiler instead of using the prebuilt libraries fixed it.

I did it but I still get the same error.

Could you show me how to it? I’m still new to zig.

I’ve never built sdl either, but there should be build instructions in the repository somewhere.

If that’s too difficult you could also try using the dll instead of linking the static library.

Start with: GitHub - andrewrk/sdl-zig-demo: SDL2 hello world in zig
based on: GitHub - allyourcodebase/SDL: SDL with the build system replaced by Zig

or with: GitHub - ikskuh/SDL.zig: A shallow wrapper around SDL that provides object API and error handling

1 Like

I used SDL.zig and it works now. Thanks a lot!