Monday 28 September 2015

SDL2.0 Complete Installation on Ubuntu

I've just spent sometime, setting up SDL for development on my Ubuntu machine, and found that the Ubuntu library caches lack SDL v2.0, they have the older 1.2, but that wasn't good enough, so here is a little script I've put together, to get me all the dependencies (least what I think the dependencies are), download each part of SDL (SDL, TTF, Mixer & Image), extract them into folders, build and install them, and then delete the folder copy which was extracted.

cd ~
sudo apt-get install build-essential xorg-dev libudev-dev libts-dev libgl1-mesa-dev libglu1-mesa-dev libasound2-dev libpulse-dev libopenal-dev libogg-dev libvorbis-dev libaudiofile-dev libpng12-dev libfreetype6-dev libusb-dev libdbus-1-dev zlib1g-dev libdirectfb-dev
wget https://www.libsdl.org/release/SDL2-2.0.3.tar.gz
tar -xvzf SDL2-2.0.3.tar.gz
cd SDL2*
./configure
make
sudo make install
cd ~
rm -rf SDL2-2*
wget https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.0.tar.gz
tar -xvzf SDL2_image-2.0.0.tar.gz
cd SDL2_image*
./configure
make
sudo make install
cd ~
rm -rf SDL2_image*
wget https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.12.tar.gz
tar -xvzf SDL2_ttf-2.0.12.tar.gz
cd SDL2_ttf*
./configure
make all
sudo make install
cd ~
rm -rf SDL2_ttf*
wget https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.0.tar.gz
tar -xvzf SDL2_mixer-2.0.0.tar.gz
cd SDL2_mixer*
./configure
make all
sudo make install
cd ~
rm -rf SDL2_mixer*
sudo ldconfig

Once this is all done, you need to edit /etc/ld.so.conf adding to it, thus:

sudo nano /etc/ld.so.conf

And add:

include /usr/local/lib

Save the file, I can now create an empty C++ project, or just a main.cpp, and include the following files:

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>

The libraries to link against are:

libSDL2.a
libSDL2_image.a
libSDL2main.a
libSDL2_mixer.a
libSDL2_test.a
libSDL2_ttf.a

(Each .a also has a static .so, alongside, if you prefer)

This, of course the linker options on the command line are:

g++ --std=c++11 main.cpp -llibSDL2.a -llibSDL2_image.a -llibSDL2main.a -llibSDL2_mixer.a -llibSDL2_test.a -llibSDL2_ttf.a

No comments:

Post a Comment