# How to install sdl3 library?

**URL:** <https://ziggit.dev/t/how-to-install-sdl3-library/9237>\
**Category:** Help\
**Tags:** language, build-system\
**Created:** [March 25, 2025, 3:45am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237 "2025-03-25T03:45:13Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![ahmet111](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@ahmet111](https://ziggit.dev/u/ahmet111)\
**Post date:** [March 27, 2025, 12:21am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/21 "2025-03-27T00:21:14Z")

</div>

```zig
const std = @import("std");

pub const std_options: std.Options = .{
    .log_level = .debug,
};

const c = @cImport({
    @cDefine("SDL_DISABLE_OLD_NAMES", {});
    @cInclude("SDL3/SDL.h");
    @cInclude("SDL3/SDL_revision.h");
    // For programs that provide their own entry points instead of relying on SDL's main function
    // macro magic, 'SDL_MAIN_HANDLED' should be defined before including 'SDL_main.h'.
    @cDefine("SDL_MAIN_HANDLED", {});
    @cInclude("SDL3/SDL_main.h");
});

```

Ok, I copied the above codes to the main.zig file in src. What should I do now?

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [March 27, 2025, 12:30am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/22 "2025-03-27T00:30:20Z")

</div>

Try to create a more minimal version of the `main` function:

> <https://github.com/castholm/zig-examples/blob/77a829c85b5ddbad673026d504626015db4093ac/breakout/main.zig#L54>

Throwing out stuff like audio, drawing of bricks, etc. only keeping the essential skeleton of the function and try to read and understand what the different parts do. I think that would set you up to have a good understanding of how you can build an sdl application.

And then try whether it can be run via `zig build run`

---

<div class="post-metadata">

**Author:** ![ahmet111](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@ahmet111](https://ziggit.dev/u/ahmet111)\
**Post date:** [March 27, 2025, 12:45am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/23 "2025-03-27T00:45:39Z")

</div>

I copied the following into the main.zig file.

```zig
const std = @import("std");
const sdl = @cImport(@cInclude("SDL3/SDL.h"));

pub fn main() !void {
    
    if (sdl.SDL_Init(sdl.SDL_INIT_VIDEO) != 0) {
        std.debug.print("SDL Başlatma Hatası: {s}\n", .{sdl.SDL_GetError()});
        return;
    }

   
    const window = sdl.SDL_CreateWindow(
        "Zig SDL3 Örneği",
        640, 480, sdl.SDL_WINDOW_VISIBLE,
    );

    if (window == null) {
        std.debug.print("Pencere oluşturma hatası: {s}\n", .{sdl.SDL_GetError()});
        sdl.SDL_Quit();
        return;
    }

    
    sdl.SDL_Delay(3000);

    
    sdl.SDL_DestroyWindow(window);
    sdl.SDL_Quit();
}

```

I did a zig build.

```zig
zig build
thread 14632 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\5aefe6b7d31252c1': FileNotFound

```

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [March 27, 2025, 12:47am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/24 "2025-03-27T00:47:38Z")

</div>

did you run the `zig fetch` command after updating zig

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [March 27, 2025, 12:48am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/25 "2025-03-27T00:48:16Z")

</div>

What is in your `build.zig.zon`?

---

<div class="post-metadata">

**Author:** ![ahmet111](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@ahmet111](https://ziggit.dev/u/ahmet111)\
**Post date:** [March 27, 2025, 12:49am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/26 "2025-03-27T00:49:46Z")

</div>

zig fetch did not work at all without the update. it worked after the update.

---

<div class="post-metadata">

**Author:** ![ahmet111](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@ahmet111](https://ziggit.dev/u/ahmet111)\
**Post date:** [March 27, 2025, 12:51am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/27 "2025-03-27T00:51:44Z")

</div>

The build.zig.zon file is not in the folder I am working in. I don’t know where it is.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [March 27, 2025, 12:53am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/28 "2025-03-27T00:53:50Z")

</div>

It is there:

> [@ahmet111](#):
>
> `'D:\oyun-zig\build.zig.zon'`

But it should be in the same folder as your `build.zig`, move it there.

And execute `zig build` etc. from your project folder.

---

<div class="post-metadata">

**Author:** ![ahmet111](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@ahmet111](https://ziggit.dev/u/ahmet111)\
**Post date:** [March 27, 2025, 12:57am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/29 "2025-03-27T00:57:24Z")

</div>

I looked inside the oyun-zig folder. A file named build.zig.zon was not created. There is none. Only a folder named .zig-cache was created. Multiple folders and files were created inside it. I looked at each one one by one. There is no file named build.zig.zon in any of them.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [March 27, 2025, 12:58am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/30 "2025-03-27T00:58:54Z")

</div>

Can you re-execute the `zig fetch` making sure you are inside the folder that contains your `build.zig`?

The `zig init` should have created these files.

I think you may have executed `zig init` in a wrong directory?

---

<div class="post-metadata">

**Author:** ![ahmet111](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@ahmet111](https://ziggit.dev/u/ahmet111)\
**Post date:** [March 27, 2025, 1:04am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/31 "2025-03-27T01:04:58Z")

</div>

cd /d D:\oyun-zig

D:\oyun-zig\>zig build  
I’m doing this.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [March 27, 2025, 1:06am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/32 "2025-03-27T01:06:32Z")

</div>

> [@ahmet111](#):
>
> D:\oyun-zig

This is your project directory?  
Have you ever called `zig init` in there?

It should have written something like:

```zig
info: created build.zig
info: created build.zig.zon
info: created src/main.zig
info: created src/root.zig
info: see `zig build --help` for a menu of options

```

---

<div class="post-metadata">

**Author:** ![ahmet111](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@ahmet111](https://ziggit.dev/u/ahmet111)\
**Post date:** [March 27, 2025, 1:09am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/33 "2025-03-27T01:09:04Z")

</div>

yes. my game is in this folder. it is in the game-zig folder in the d drive. the build and main files are in this folder. i don’t understand where zig init is and what it does.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [March 27, 2025, 1:11am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/34 "2025-03-27T01:11:20Z")

</div>

`zig init` is a command that initializes a new zig project and creates some basic files for a project, similar to how `zig build` is a command that builds a zig project

---

<div class="post-metadata">

**Author:** ![ahmet111](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@ahmet111](https://ziggit.dev/u/ahmet111)\
**Post date:** [March 27, 2025, 1:24am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/35 "2025-03-27T01:24:12Z")

</div>

I read articles about how to create a project. I couldn’t succeed. I asked chatgpt last. He suggested 30-40 steps. I kept getting errors with each suggestion. He kept updating the codes. He made adjustments. But I never succeeded. He gave various errors every time. When I couldn’t solve the problem, he finally told me to create it manually. I created a folder called oyun-zig in the D drive. There is a src folder in it. There is a file called main.zig in it. There is also build.zig in the main directory. He said that creating these folders and files would be enough. I couldn’t do that as you mentioned, creating a project from the console. I got 40 different errors in 40 attempts.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [March 27, 2025, 1:26am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/36 "2025-03-27T01:26:12Z")

</div>

```zig
D:\oyun-zig>zig init

```

gives what output?

---

<div class="post-metadata">

**Author:** ![ahmet111](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@ahmet111](https://ziggit.dev/u/ahmet111)\
**Post date:** [March 27, 2025, 1:28am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/37 "2025-03-27T01:28:07Z")

</div>

> [@Sze](#):
>
> `D:\oyun-zig>zig init`

D:\oyun-zig\>zig init  
‘D:\oyun-zig’ is not recognized as an internal or external command,  
operable program or batch file.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [March 27, 2025, 1:33am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/38 "2025-03-27T01:33:46Z")

</div>

No, you need to navigate to the folder and then execute `zig init` as command, similar to how you ran `zig build`.

---

<div class="post-metadata">

**Author:** ![ahmet111](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@ahmet111](https://ziggit.dev/u/ahmet111)\
**Post date:** [March 27, 2025, 1:40am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/39 "2025-03-27T01:40:54Z")

</div>

cd /d D:\oyun-zig

D:\oyun-zig\>zig init  
info: preserving already existing file: build.zig  
info: created build.zig.zon  
info: preserving already existing file: src\main.zig  
info: created src\root.zig

---

<div class="post-metadata">

**Author:** ![ahmet111](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@ahmet111](https://ziggit.dev/u/ahmet111)\
**Post date:** [March 27, 2025, 1:43am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/40 "2025-03-27T01:43:17Z")

</div>

The files you mentioned have been created.  
I did a zig build run again.  
the result is below.  
D:\oyun-zig\>cd /d D:\oyun-zig

D:\oyun-zig\>zig build run  
thread 8788 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\6a1991fc34c5034e’: FileNotFound

[Previous page](https://ziggit.dev/t/how-to-install-sdl3-library/9237.md?page=1)

[Next page](https://ziggit.dev/t/how-to-install-sdl3-library/9237.md?page=3)
