How to install sdl3 library?

Now you need to execute the zig fetch again:

zig fetch --save git+https://github.com/castholm/SDL.git

it adds the sdl dependency to your build.zig.zon

zig fetch --save git+https://github.com/castholm/SDL.git
info: resolved to commit dbb1…
info: existing dependency named ‘sdl’ is up-to-date

does zig build run work?
Otherwise what is the content of the build.zig.zon?

zig build run result.

cd /d D:\oyun-zig

D:\oyun-zig>zig build run
thread 2988 panic: no dependency named ‘sdl’ in ‘D:\oyun-zig\build.zig.zon’. All packages used in build.zig must be declared in this file
C:\zig\lib\std\Build.zig:2159:20: 0x7ff6e388f838 in findPkgHashOrFatal (build.exe.obj)
std.debug.panic(“no dependency named ‘{s}’ in ‘{s}’. All packages used in build.zig must be declared in this file”, .{ name, full_path });
^
C:\zig\lib\std\Build.zig:2222:40: 0x7ff6e3871e4e in dependency__anon_67208 (build.exe.obj)
const pkg_hash = findPkgHashOrFatal(b, name);
^
D:\oyun-zig\build.zig:17:33: 0x7ff6e3861a68 in build (build.exe.obj)
const sdl_dep = b.dependency(“sdl”, .{
^
C:\zig\lib\std\Build.zig:2427:33: 0x7ff6e3857ce2 in runBuild__anon_27568 (build.exe.obj)
.void => build_zig.build(b),
^
C:\zig\lib\compiler\build_runner.zig:339:29: 0x7ff6e3850e27 in main (build.exe.obj)
try builder.runBuild(root);
^
C:\zig\lib\std\start.zig:475:53: 0x7ff6e385a0ef in WinStartup (build.exe.obj)
std.os.windows.ntdll.RtlExitUserProcess(callMain());
^
???:?:?: 0x7ffd2d297373 in ??? (KERNEL32.DLL)
???:?:?: 0x7ffd2e2bcc90 in ??? (ntdll.dll)
error: unable to read results of configure phase from ‘D:\oyun-zig.zig-cache\tmp\0d55bf04023a21f9’: FileNotFound

.{
    // This is the default name used by packages depending on this one. For
    // example, when a user runs `zig fetch --save <url>`, this field is used
    // as the key in the `dependencies` table. Although the user can choose a
    // different name, most users will stick with this provided value.
    //
    // It is redundant to include "zig" in this name because it is already
    // within the Zig package namespace.
    .name = .oyun_zig,

    // This is a [Semantic Version](https://semver.org/).
    // In a future version of Zig it will be used for package deduplication.
    .version = "0.0.0",

    // Together with name, this represents a globally unique package
    // identifier. This field is generated by the Zig toolchain when the
    // package is first created, and then *never changes*. This allows
    // unambiguous detection of one package being an updated version of
    // another.
    //
    // When forking a Zig project, this id should be regenerated (delete the
    // field and run `zig build`) if the upstream project is still maintained.
    // Otherwise, the fork is *hostile*, attempting to take control over the
    // original project's identity. Thus it is recommended to leave the comment
    // on the following line intact, so that it shows up in code reviews that
    // modify the field.
    .fingerprint = 0xc5157bbfc8810127, // Changing this has security and trust implications.

    // Tracks the earliest Zig version that the package considers to be a
    // supported use case.
    .minimum_zig_version = "0.15.0-dev.117+1408288b9",

    // This field is optional.
    // Each dependency must either provide a `url` and `hash`, or a `path`.
    // `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
    // Once all dependencies are fetched, `zig build` no longer requires
    // internet connectivity.
    .dependencies = .{
        // See `zig fetch --save <url>` for a command-line interface for adding dependencies.
        //.example = .{
        //    // When updating this field to a new URL, be sure to delete the corresponding
        //    // `hash`, otherwise you are communicating that you expect to find the old hash at
        //    // the new URL. If the contents of a URL change this will result in a hash mismatch
        //    // which will prevent zig from using it.
        //    .url = "https://example.com/foo.tar.gz",
        //
        //    // This is computed from the file contents of the directory of files that is
        //    // obtained after fetching `url` and applying the inclusion rules given by
        //    // `paths`.
        //    //
        //    // This field is the source of truth; packages do not come from a `url`; they
        //    // come from a `hash`. `url` is just one of many possible mirrors for how to
        //    // obtain a package matching this `hash`.
        //    //
        //    // Uses the [multihash](https://multiformats.io/multihash/) format.
        //    .hash = "...",
        //
        //    // When this is provided, the package is found in a directory relative to the
        //    // build root. In this case the package's hash is irrelevant and therefore not
        //    // computed. This field and `url` are mutually exclusive.
        //    .path = "foo",
        //
        //    // When this is set to `true`, a package is declared to be lazily
        //    // fetched. This makes the dependency only get fetched if it is
        //    // actually used.
        //    .lazy = false,
        //},
    },

    // Specifies the set of files and directories that are included in this package.
    // Only files and directories listed here are included in the `hash` that
    // is computed for this package. Only files listed here will remain on disk
    // when using the zig package manager. As a rule of thumb, one should list
    // files required for compilation plus any license(s).
    // Paths are relative to the build root. Use the empty string (`""`) to refer to
    // the build root itself.
    // A directory listed here means that all files within, recursively, are included.
    .paths = .{
        "build.zig",
        "build.zig.zon",
        "src",
        // For example...
        //"LICENSE",
        //"README.md",
    },
}

You didn’t execute the zig fetch in your project folder, but somewhere else.
That is why it didn’t add sdl as a dependency to the build.zig.zon, my guess is that it was added to some other build.zig.zon that is located somewhere else.

I did zig fetch exactly as you said. Finally, zig.zon file and root.zig files were created automatically. I don’t know how to run fetch anywhere else.

did you run it inside the project folder or in some other folder?

The file named build.zig.zon was not in the game-zig folder. It created it automatically. And it added the texts I sent you in it automatically. I don’t know where else it adds it or how it adds it.

I don’t fully understand what it means to run it in a project folder. I’ve never used Linux. I have zero knowledge of the Linux terminal. I can only use Windows. I ran all the codes you gave me on the console. I copied and pasted and ran it.

This in your console shows the folder/directory where your console currently is.
When you run the zig fetch command it needs to be in the folder where the build.zig and build.zig.zon are.

You can use dir in console to list the contents of the current folder where the console is.

D:\oyun-zig>
The syntax of the command is incorrect.

Shouldn’t I be in oyun-zig when I write like this? Why did it give such an error?

you don’t type that in that is what your console should show as prompt, the prompt shows where the console is.

You use cd to navigate to the folder, like you have done before.

C:\Users\XX>cd D:\oyun-zig

C:\Users\XX>zig fetch --save git+https://github.com/castholm/SDL.git
info: resolved to commit dbb1b96360658f5845ff6fac380c4f13d7276dc2
info: existing dependency named ‘sdl’ is up-to-date

D:
cd oyun-zig
dir

Directory of D:\oyun-zig

27.03.2025 04:38 .
27.03.2025 04:38 …
27.03.2025 03:39 .zig-cache
27.03.2025 02:59 841 build.zig
27.03.2025 04:38 4.316 build.zig.zon
27.03.2025 04:38 src
2 File(s) 5.157 bytes
4 Dir(s) 304.064.708.608 bytes free

now:

zig fetch --save git+https://github.com/castholm/SDL.git
zig build run

D:\oyun-zig>zig fetch --save git+https://github.com/castholm/SDL.git
info: resolved to commit dbb1b96360658f5845ff6fac380c4f13d7276dc2

D:\oyun-zig>zig build run
run
└─ run breakout
└─ install
└─ install breakout
└─ zig build-exe breakout Debug native 1 errors
error: failed to check cache: ‘main.zig’ file_hash FileNotFound
error: the following command failed with 1 compilation errors:
C:\zig\zig.exe build-exe D:\oyun-zig.zig-cache\o\b8a31048b1c4056d5c891c5def0fdfc7\SDL3.lib -ODebug -I D:\oyun-zig.zig-cache\o\0acc5620de2d781ff496ea20c3a797d9 -Mroot=D:\oyun-zig\main.zig D:\oyun-zig.zig-cache\o\817f1dcf5033dc59c0f9acfadbb54548\SDL_uclib.lib -lkernel32 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lversion -ladvapi32 -lsetupapi -lshell32 -ldinput8 -lc --cache-dir D:\oyun-zig.zig-cache --global-cache-dir C:\Users\XX\AppData\Local\zig --name breakout --zig-lib-dir C:\zig\lib\ –listen=-
Build Summary: 6/11 steps succeeded; 1 failed
run transitive failure
└─ run breakout transitive failure
├─ zig build-exe breakout Debug native 1 errors
└─ install transitive failure
└─ install breakout transitive failure
└─ zig build-exe breakout Debug native (+3 more reused dependencies)
error: the following build command failed with exit code 1:
D:\oyun-zig.zig-cache\o\c3760f3487daa9a327379361b7f1d440\build.exe C:\zig\zig.exe C:\zig\lib D:\oyun-zig D:\oyun-zig.zig-cache C:\Users\XX\AppData\Local\zig --seed 0x1083fd6b -Za1dd044a9892a166 run