Skip to content

Instantly share code, notes, and snippets.

@NoxFly
Last active April 30, 2025 16:47
Show Gist options
  • Save NoxFly/1067c9fc24024d26b51a6825de5cff74 to your computer and use it in GitHub Desktop.
Save NoxFly/1067c9fc24024d26b51a6825de5cff74 to your computer and use it in GitHub Desktop.
SDL3 installation guide

SDL3 installation guide

Last modified date : 2025-04-30

This covers the installation of SDL3 on a Unix system based on Debian (with apt).
Contribute to cover more systems.

Below explanations are if you plan to build the whole library from sources of the official Github repository.

Download and installation

Step 1 : Download

From the global SDL organization on Github, download the zip of these packages :

Package name version repository URL description
Core 3.0 https://github.com/libsdl-org/SDL Core required package
SDL_image 3.0 https://github.com/libsdl-org/SDL_image Used for images and textures
SDL_ttf 3.0 https://github.com/libsdl-org/SDL_ttf Used for text and fonts managment
SDL_mixer 3.0 https://github.com/libsdl-org/SDL_mixer Used for audio
SDL_net 2.0 https://github.com/libsdl-org/SDL_net Used for networking

Step 2 : installation process

The process for each package will be the same.
However, some will require other packages, otherwise it won't build.

Packages that have dependencies :

Package name dependency guide for installation
SDL_ttf freetype go to chapter
# assuming you are in ~/Download folder, with all SDL*.zip in it

# 1. setup
mkdir SDL3_setup && cd SDL3_setup
mv ../SDL*.zip .
mkdir build

# Repeat step 2 and 3 for each packages you want to install

# 2. prepare for the desired package
unzip SDL-main.zip
# optional step
rm -rf ./build/* # clean folder for next installation

# 3. build and install
cd build
cmake ../SDL-<package-name>/CMakeLists.txt -B .
make
sudo make install

Dependencies installation guide

Freetype

Go on the official download page and click on the sourceforge link.

Download the tar.xz file.

Extract with tar -xf freetype-<version>.tar.xz, replacing <version> by the version you have, then move inside the extracted folder.

You can find documentation for the installation depending your system, in the doc/ folder.

Then build the package :

sh autogen.sh
./configure # this will install in /usr/local. See --help for moving target
make
sudo make install

Minimal Code Example

#include <iostream>
#include <SDL3/SDL.h>

int main(int argc, char **argv) {
	if(SDL_Init(SDL_InitFlags::SDL_INIT_VIDEO) < 0) {
		std::cerr << "Init error : " << SDL_GetError() << std::endl;
		return EXIT_FAILURE;
	}

	auto window = SDL_CreateWindowWithPosition(
		"MCE",
		SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
		720, 405,
		SDL_WindowFlags::SDL_WINDOW_OPENGL
	);

	if(!window) {
		std::cerr << "Window creation error : " << SDL_GetError() << std::endl;
		SDL_Quit();
        	return EXIT_FAILURE;
	}

	bool isRunning = true;

	while(isRunning) {
		// render here

		// input
		SDL_Event event;

		while(SDL_PollEvent(&event)) {
			switch(event.type) {
				case SDL_EventType::SDL_EVENT_QUIT:
					isRunning = false;
					break;
			}
		}
	}

	SDL_Quit();

	return EXIT_SUCCESS;
}
@NoxFly
Copy link
Author

NoxFly commented Mar 29, 2025

"Go on and click on the sourceforge link."

What link? Where?

@dmars8047
You are right, the link is missing. I'm adding it.

@kuliok1
Copy link

kuliok1 commented Apr 21, 2025

how to run the file, or to just use g++?

@NoxFly
Copy link
Author

NoxFly commented Apr 21, 2025

@kuliok1 Which file ? The minimal example code ? Like any other C++ code. With an IDE, or with clang/g++.

Also, SDL has officially released the SDL3, so now we should be able to download it directly and simply via sudo apt-get install libsdl3-dev.

See here

@kuliok1
Copy link

kuliok1 commented Apr 21, 2025

ty

@Dummigame
Copy link

@kuliok1 Which file ? The minimal example code ? Like any other C++ code. With an IDE, or with clang/g++.

Also, SDL has officially released the SDL3, so now we should be able to download it directly and simply via sudo apt-get install libsdl3-dev.

See here

I should have looked at this before going through the whole process
There are no differences besides effort of installation, or are there things missing from my install now?

@NoxFly
Copy link
Author

NoxFly commented Apr 30, 2025

@kuliok1 Which file ? The minimal example code ? Like any other C++ code. With an IDE, or with clang/g++.
Also, SDL has officially released the SDL3, so now we should be able to download it directly and simply via sudo apt-get install libsdl3-dev.
See here

I should have looked at this before going through the whole process There are no differences besides effort of installation, or are there things missing from my install now?

@Dummigame except having a good reason to build from sources, if you plan to use SDL3 normally, you should use the classic way, by your package manager (apt, ...).
It's way easier, faster, you are sure to not have done something wrong between two steps, and you're up to date with the latest stable release.

I've added a bold remark at the top of the gist.
Thanks for your question.

@zapposh
Copy link

zapposh commented Apr 30, 2025

sudo apt-get install libsdl3-dev returns "Unable to locate package libsdl3-dev"

@NoxFly
Copy link
Author

NoxFly commented Apr 30, 2025

@zapposh As I see, of today, SDL3 is not officially released yet, thus the libsdl3-dev package is not available for now, even if the
Github releases show that there're already SDL3 releases that are made since some months.
We'll need to wait a bit longer to use a package manager tho, and manually build from sources.
When SDL3 will be officially released, the mentionned package will exist.

I apologize, I read too quickly some infos, and didn't even tried the command I showed above (apt-get install).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment