Skip to content

Instantly share code, notes, and snippets.

@aaangeletakis
Last active February 20, 2024 17:55
Show Gist options
  • Star 72 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save aaangeletakis/3187339a99f7786c25075d4d9c80fad5 to your computer and use it in GitHub Desktop.
Save aaangeletakis/3187339a99f7786c25075d4d9c80fad5 to your computer and use it in GitHub Desktop.
How do I install SDL on ubuntu?

What you need to do to install SDL is:

#install sdl2
sudo apt install libsdl2-dev libsdl2-2.0-0 -y;

#install sdl image  - if you want to display images
sudo apt install libjpeg-dev libwebp-dev libtiff5-dev libsdl2-image-dev libsdl2-image-2.0-0 -y;

#install sdl mixer  - if you want sound
sudo apt install libmikmod-dev libfishsound1-dev libsmpeg-dev liboggz2-dev libflac-dev libfluidsynth-dev libsdl2-mixer-dev libsdl2-mixer-2.0-0 -y;

#install sdl true type fonts - if you want to use text
sudo apt install libfreetype6-dev libsdl2-ttf-dev libsdl2-ttf-2.0-0 -y;

use

`sdl2-config --cflags --libs` -lSDL2 -lSDL2_mixer -lSDL2_image -lSDL2_ttf

to link them, for example:

g++ myProgram.cpp -o myProgram `sdl2-config --cflags --libs` -lSDL2 -lSDL2_mixer -lSDL2_image -lSDL2_ttf

if you would like to install all the packages at once, copy and paste this into your terminal

#Oneliner to do the above install
sudo apt update && bash <(wget -qO - https://boredbored.net/sdl2-install)
@s0kil
Copy link

s0kil commented Aug 8, 2018

Thanks!

@Terabyte04
Copy link

Thanks so much!

@mehdibalbali
Copy link

Thanks !

@babu-the-braveheart
Copy link

i got this error on second command;

Errors were encountered while processing:
/var/cache/apt/archives/libjpeg9-dev_1%3a9b-1ubuntu1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

and this sdl2-config --cflags --libs -lSDL2 -lSDL2_mixer -lSDL2_image -lSDL2_ttf
bash: -I/usr/include/SDL2: No such file or directory

any guides to help me understand better. thanks

@BrittMcDanel
Copy link

Thanks!!

@edjeordjian
Copy link

i got this error on second command;

Errors were encountered while processing:
/var/cache/apt/archives/libjpeg9-dev_1%3a9b-1ubuntu1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

I just ran:
sudo apt install libwebp-dev libtiff5-dev libsdl2-image-dev libsdl2-image-2.0-0 -y;

(omitting libjpeg9) an seems to work fine.

and this sdl2-config --cflags --libs -lSDL2 -lSDL2_mixer -lSDL2_image -lSDL2_ttf
bash: -I/usr/include/SDL2: No such file or directory

I did not use the last two commands. Instead, I just compiled (a really simple program to test sdl) with:
g++ myTest.cpp -o myTest -lSDL2

And then ran the test with:
./myTest

If you are using CLion, just add at the end of the CMakeList:
target_link_libraries(PROJECT_NAME_HERE SDL2)

where PROJECT_NAME_HERE is the name of the first executable in the "add_executable" line (the name of the project's folder). Eventually, you may need to link more than just sdl2:

target_link_libraries(PROJECT_NAME_HERE SDL2 SDL2_image SDL2_ttf SDL2_mixer).

@nmharmon8
Copy link

Thanks

@iuri
Copy link

iuri commented May 1, 2020

i got this error on second command;
Errors were encountered while processing:
/var/cache/apt/archives/libjpeg9-dev_1%3a9b-1ubuntu1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

I just ran:
sudo apt install libwebp-dev libtiff5-dev libsdl2-image-dev libsdl2-image-2.0-0 -y;

(omitting libjpeg9) an seems to work fine.

and this sdl2-config --cflags --libs -lSDL2 -lSDL2_mixer -lSDL2_image -lSDL2_ttf
bash: -I/usr/include/SDL2: No such file or directory

I did not use the last two commands. Instead, I just compiled (a really simple program to test sdl) with:
g++ myTest.cpp -o myTest -lSDL2

And then ran the test with:
./myTest

If you are using CLion, just add at the end of the CMakeList:
target_link_libraries(PROJECT_NAME_HERE SDL2)

where PROJECT_NAME_HERE is the name of the first executable in the "add_executable" line (the name of the project's folder). Eventually, you may need to link more than just sdl2:

target_link_libraries(PROJECT_NAME_HERE SDL2 SDL2_image SDL2_ttf SDL2_mixer).

You should change libjpg9-dev deb pkg to libjpeg-dev only. That way apt will start the available default pkg to your distro. In my case Ubuntu 18.04 (Bionic) is libjpeg8-dev. Hope it helps.

sudo apt install libjpeg-dev libwebp-dev libtiff5-dev libsdl2-image-dev libsdl2-image-2.0-0 -y;

Best wishes,
I

@aaangeletakis
Copy link
Author

i got this error on second command;
Errors were encountered while processing:
/var/cache/apt/archives/libjpeg9-dev_1%3a9b-1ubuntu1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

I just ran:
sudo apt install libwebp-dev libtiff5-dev libsdl2-image-dev libsdl2-image-2.0-0 -y;
(omitting libjpeg9) an seems to work fine.

and this sdl2-config --cflags --libs -lSDL2 -lSDL2_mixer -lSDL2_image -lSDL2_ttf
bash: -I/usr/include/SDL2: No such file or directory

I did not use the last two commands. Instead, I just compiled (a really simple program to test sdl) with:
g++ myTest.cpp -o myTest -lSDL2
And then ran the test with:
./myTest
If you are using CLion, just add at the end of the CMakeList:
target_link_libraries(PROJECT_NAME_HERE SDL2)
where PROJECT_NAME_HERE is the name of the first executable in the "add_executable" line (the name of the project's folder). Eventually, you may need to link more than just sdl2:
target_link_libraries(PROJECT_NAME_HERE SDL2 SDL2_image SDL2_ttf SDL2_mixer).

You should change libjpg9-dev deb pkg to libjpeg-dev only. That way apt will start the available default pkg to your distro. In my case Ubuntu 18.04 (Bionic) is libjpeg8-dev. Hope it helps.

sudo apt install libjpeg-dev libwebp-dev libtiff5-dev libsdl2-image-dev libsdl2-image-2.0-0 -y;

Best wishes,
I

Will do

@felipe434
Copy link

thanks

@omonimus1
Copy link

omonimus1 commented Jul 30, 2020

Very useful, thank you a lot!

@vmabuza
Copy link

vmabuza commented Aug 4, 2020

I get the following error when I try to compile smc

`$ ./configure
checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking target system type... x86_64-unknown-linux-gnu

checking for a BSD-compatible install... /usr/bin/install -c

checking whether build environment is sane... yes

checking for a thread-safe mkdir -p... /usr/bin/mkdir -p

checking for gawk... gawk

checking whether make sets $(MAKE)... yes

checking for g++... g++

checking for C++ compiler default output file name... a.out

checking whether the C++ compiler works... yes

checking whether we are cross compiling... no

checking for suffix of executables...

checking for suffix of object files... o

checking whether we are using the GNU C++ compiler... yes

checking whether g++ accepts -g... yes

checking for style of include used by make... GNU

checking dependency style of g++... gcc3

checking for main in -lboost_filesystem... yes

checking for main in -lGL... yes

checking for main in -lGLU... yes

checking for pkg-config... /usr/bin/pkg-config

checking pkg-config is at least version 0.9.0... yes

checking for SDL... yes

checking for png_init_io in -lpng... yes

checking for IMG_LoadPNG_RW in -lSDL_image... no

configure: error: SDL_image library with PNG support not found
`

I ran

$ sudo apt install libpng-dev

but I still get the same error, can someone please help me install the PNG libraries.

@aaangeletakis
Copy link
Author

What is SMC?
@vmabuza

@NoahAncolie
Copy link

THAnks ! A lot!

@aaangeletakis
Copy link
Author

Copy link

ghost commented Feb 16, 2021

I made a Bash script out of this: https://github.com/d26900/Scripts/blob/main/setup.sh

Run it like so: sudo bash setup.sh

If you just want to install the SDL libraries, comment out the other run_installs with a #.
The only thing you need is: run_installs "apt install" "-y" "${apts_sdl[@]}"

@aaangeletakis
Copy link
Author

How is this different from the script I made?
bash <(wget -qO - https://boredbored.net/sdl2-install)

@wpichl
Copy link

wpichl commented Feb 16, 2021

works! thank you! had sum errors but you fixed it!

@aaangeletakis
Copy link
Author

:P

Copy link

ghost commented Feb 19, 2021

How is this different from the script I made?
bash <(wget -qO - https://boredbored.net/sdl2-install)

I wasn't aware of your script, but yours is more concise & short. I designed my Bash script to be more adjustable for different kinds of installs (apt, npm, pip etc.). All you need to do is add the package name to a list pips=("numpy", ...) and then call the run_installs function like so:

run_installs "pip3 install" "" "${pips[@]}"

The first argument is the command, the second argument is an option and the last argument is the list of packages/modules you want to install all at once. Here's another example:

run_installs "apt install" "-y" "${apts_sdl[@]}"

Same structure: <commands> <options> <packages>

Then you need that script as sudo bash setup.sh. Done!

@mmdbalkhi
Copy link

Thankful!

@GH4169
Copy link

GH4169 commented Aug 1, 2023

Thankful!

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