# 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:** 1

<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 25, 2025, 3:45am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/1 "2025-03-25T03:45:13Z")

</div>

I tried many ways and couldn’t install it. How can I install it? Is there a source that explains it step by step?

---

<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 25, 2025, 8:27am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/2 "2025-03-25T08:27:34Z")

</div>

assuming your talking about adding it as a dependency

> **[GitHub - castholm/SDL: SDL ported to the Zig build system](https://github.com/castholm/SDL)**
>
> SDL ported to the Zig build system

---

<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 26, 2025, 7:27pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/3 "2025-03-26T19:27:16Z")

</div>

I couldn’t understand what was in the link you gave. How to set it up? How will it work? Is there a step-by-step article or video explaining 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 26, 2025, 7:48pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/4 "2025-03-26T19:48:23Z")

</div>

Have you looked at the examples?

> **[zig-examples/breakout at master · castholm/zig-examples](https://github.com/castholm/zig-examples/tree/master/breakout)**
>
> Collection of small Zig example projects. Contribute to castholm/zig-examples development by creating an account on GitHub.

I think wanting a video tutorial for every specific thing is a trap that can keep you from learning how to progress and become self-reliant, I think instead it is better to learn how to utilize general learning materials (including videos, blog posts / articles, etc.) to build your skills and fill in gaps in your knowledge.

Let us know what topics specifically you need help with, so we can point you to resources that are about that topic. We don’t know what you know, or don’t know.

It doesn’t make sense to make a “how to start from nothing” tutorial for every project you could create with a programming language.

Here are some general learning resources:

> [@Zig Learning Resources](https://ziggit.dev/t/zig-learning-resources/3160):
>
> Zig is still a relatively young programming language and yet to reach a 1.0 release. This is why it’s rapidly evolving and breaking changes between releases are expected. This makes it a hard moving target when trying to develop and maintain learning resources about the language and its ecosystem. Nevertheless, there are already some very good resources available and we invite the community to add their own and help keep this list up-to-date. The list is not in any particular order to make it ea…

Do these help you?  
If not, what do you need help with?

---

<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 26, 2025, 7:58pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/5 "2025-03-26T19:58:32Z")

</div>

I can’t use the sld3 library with zig. I looked at articles and videos about what to do at first. and none of them helped me. I asked chatgpt. All of the dozens of suggestions he gave me came up with errors. I can’t find a solution. I couldn’t even get an sdl output that would write text to the screen at the simplest level. I’m looking for a source that will explain this step by step. There aren’t many sources about the zig language. The examples you gave are quite complicated and are made into games. I couldn’t include the sld3 library either.

---

<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 26, 2025, 8:38pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/6 "2025-03-26T20:38:11Z")

</div>

- create a new zig project using `zig init`
- add the sdl dependency by using `zig fetch`
- add the dependency and import to your `build.zig`
- add the `@import` to the code
- change the code to be equivalent to a simple sdl example

I think all these steps are simple steps you should be able to figure out mostly on your own, by making use of the learning resources / using existing answers, or at least tell us where you got error messages.

I am not going to spoon-feed you a customized tutorial, get to work and ask questions if you get stuck.

---

<div class="post-metadata">

**Author:** ![LucasSantos91](https://ziggit.dev/user_avatar/ziggit.dev/lucassantos91/32/440_2.png) [@LucasSantos91](https://ziggit.dev/u/LucasSantos91)\
**Post date:** [March 26, 2025, 8:41pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/7 "2025-03-26T20:41:58Z")

</div>

Did you try using Castholm’s port that was linked above? It’s pretty much plug and play.  
Also, you can compile SDL3 with a C compiler and just link the static library with zig. This is the closest to the intended way of using the library.  
You haven’t made it clear how experienced you are with tools. In order to help you, we would need to know if you are experienced with C, SDL or 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 26, 2025, 8:53pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/8 "2025-03-26T20:53:24Z")

</div>

- add the sdl dependency by using `zig fetch`
- How do I do this step?

---

<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 26, 2025, 8:55pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/9 "2025-03-26T20:55:48Z")

</div>

Castholm’  
I don’t understand how to use this.  
I have little knowledge about c and zig. I am a beginner.

---

<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 26, 2025, 8:56pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/10 "2025-03-26T20:56:04Z")

</div>

> **[GitHub - castholm/SDL: SDL ported to the Zig build system](https://github.com/castholm/SDL?tab=readme-ov-file#usage)**
>
> SDL ported to the Zig build system

The zig fetch line under the usage headline.

---

<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 26, 2025, 9:01pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/11 "2025-03-26T21:01:38Z")

</div>

C:\Users\XX\>zig fetch --save git+https://github.com/castholm/SDL.git  
C:\Users\XX\AppData\Local\zig\tmp\a675f85c09fa1f87\build.zig.zon:5:14: error: expected string literal  
.name = .sdl,

---

<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 26, 2025, 9:02pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/12 "2025-03-26T21:02:33Z")

</div>

what is the output of?:

```zig
zig version

```

---

<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 26, 2025, 9:08pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/13 "2025-03-26T21:08:27Z")

</div>

zig version  
0.13.0

---

<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 26, 2025, 9:09pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/14 "2025-03-26T21:09:21Z")

</div>

You need to get zig 0.14.0 the readme of sdl states that it requires it. (at least that is simpler than using an older version of the sdl library)

---

<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 26, 2025, 11:53pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/15 "2025-03-26T23:53:34Z")

</div>

info: resolved to commit  
I did the fetch step. This article appeared. I made the version 15.0. How do I do the next step?

---

<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 26, 2025, 11:56pm UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/16 "2025-03-26T23:56:32Z")

</div>

> [@Sze](#):
>
> add the dependency and import to your `build.zig`

This one? Pretty much like here:

> <https://github.com/castholm/zig-examples/blob/master/breakout/build.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, 12:02am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/17 "2025-03-27T00:02:37Z")

</div>

I copied and pasted the codes into a file called build.zig. You said add and import the dependency. What does this mean and how should I do it?

---

<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:08am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/18 "2025-03-27T00:08:50Z")

</div>

You don’t need to add a module import, that was before I saw how the breakout example just uses `@cImport`, I think you can continue with this:

> [@SDL3 ported to the Zig build system (with example games)](https://ziggit.dev/t/sdl3-ported-to-the-zig-build-system-with-example-games/7606/16):
>
> It’s possible to use the main callbacks, but you can’t just #define SDL\_MAIN\_USE\_CALLBACKS 1 like you would in C. Instead, you have to call SDL\_EnterAppMainCallbacks() manually by passing the callbacks as function pointers. Here’s a more or less 1:1 port of their callbacks template: const c = @cImport({ @cDefine("SDL\_DISABLE\_OLD\_NAMES", {}); @cInclude("SDL3/SDL.h"); // For programs that provide their own entry points instead of relying on SDL's main function // macro magic, 'SDL…

Or you can do what

> <https://github.com/castholm/zig-examples/blob/master/breakout/main.zig>

does and remove everything you don’t need.

I think that are basically two different styles of using the library.  
The first is using callbacks and the breakout example is using a while loop.

---

<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:13am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/19 "2025-03-27T00:13:56Z")

</div>

I don’t understand. Where do I add the last codes you gave me?

---

<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:17am UTC](https://ziggit.dev/t/how-to-install-sdl3-library/9237/20 "2025-03-27T00:17:18Z")

</div>

Your `src/main.zig` needs code, personally I would start with the breakout code and step by step remove all the things that aren’t needed.

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