SDL on Linux

In my forthcoming ebook, which is the Linux equivalent of the first one I use Visual Studio Code (VSC) as the IDE to develop along with the Microsoft C/C++ extension. I’m using the SDL2 library for fast graphics and Clang as the compiler.

Thankfully Microsoft have documented most of the process of using Clang with VSC, albeit on a Mac. I’m using Ubuntu but it’s mostly the same.

Before I could configure SDL I had to add it and I never realised about apt-cache on Ubuntu (and Debian). The command

apt- cache search libsdl2

Outputs this, showing what's available.
libsdl2-2.0-0 - Simple DirectMedia Layer
libsdl2-dev - Simple DirectMedia Layer development files
libsdl2-doc - Reference manual for libsdl2
libsdl2-gfx-1.0-0 - drawing and graphical effects extension for SDL2
libsdl2-gfx-dev - development files for SDL2_gfx
libsdl2-gfx-doc - documentation files for SDL2_gfx
libsdl2-image-2.0-0 - Image loading library for Simple DirectMedia Layer 2, libraries
libsdl2-image-dev - Image loading library for Simple DirectMedia Layer 2, development files
libsdl2-mixer-2.0-0 - Mixer library for Simple DirectMedia Layer 2, libraries
libsdl2-mixer-dev - Mixer library for Simple DirectMedia Layer 2, development files
libsdl2-net-2.0-0 - Network library for Simple DirectMedia Layer 2, libraries
libsdl2-net-dev - Network library for Simple DirectMedia Layer 2, development files
libsdl2-ttf-2.0-0 - TrueType Font library for Simple DirectMedia Layer 2, libraries
libsdl2-ttf-dev - TrueType Font library for Simple DirectMedia Layer 2, development files

So a quick

sudo apt-get install libsdl2-dev

Installed 73 MB of files including all the header files. I used the files app to search for SDL files and it found a folder SDL2 in /usr/include.

And all I needed in my program was

[perl]

#include <SDL2/SDL.h>

[/perl]

And I had to add “/usr/include/SDL2/” into the includePath section of c_cpp_properties.json and “-lSDL2” into the args section of tasks.json. These two JSON files are included in C/C++ projects in VSC.

At that point I could compile and run my first SDL program on Ubuntu. It throws 10,000 random sized coloured rectangles onto the screen

The first SDL demo program

 

(Visited 420 times, 1 visits today)