25

I am having a pretty tough time installing the latest development libraries of SDL in my Ubuntu 12.04. Last year, I somehow managed to install libsdl 1.2-dev for Ubuntu. As far as I remember, I did it using Synaptic Package Manager. Now, I want to work with the latest SDL libraries. In the page containing downloads for SDL version 2.0.0 (which is the latest stable version), under Linux section for Development Libraries, it is given

Please contact your distribution maintainer for updates.

It would help me a lot if someone answered these questions:

  1. Why is it so not simple to install dev libraries in Ubuntu?
  2. Can anyone give an exhaustive list of the ways to install these libraries on the system so that one can use them for programming?
  3. It would be helpful if you can give the above answer taking the latest SDL dev libraries as an example. Also what is the procedure to clean all the previous versions from the system while installing the latest versions?

PS: I searched for the libsdl-dev package on Synaptic Package Manager, but it is not showing up the latest version.

progammer
  • 437
  • 2
  • 5
  • 11
  • Debian-based systems (including Ubuntu) can simply do "sudo apt-get install libsdl2-2.0" to get the library installed system-wide, and all sorts of other useful dependencies, too. "sudo apt-get install libsdl2-dev" will install everything necessary to build programs that use SDL (https://wiki.libsdl.org/Installation) – Dr.jacky Nov 30 '15 at 11:06

2 Answers2

23

You have to download the source and compile the libs.

You also need some dependencies before compile SDL2. So install these packages first:

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
  • Method 1: Source code archive
    Now you can go to the libsdl download page and download SDL2-2.0.0.tar.gz, extract the archive (you can extract the archive using tar: tar -xvzf SDL2-2.0.0.tar.gz), cd into the directory created, and run the following commands (don't forget to install the dependencies mentioned above, before starting to compile):

    ./configure
    make
    sudo make install
    
  • Method 2: Mercurial repository
    Another way to install SDL2 is to download SDL from the mercurial repository online. In order to do this you have to install mercurial first:

    sudo apt-get install mercurial
    

    then download SDL (SDL will be downloaded into the directory you're using the terminal)

    hg clone http://hg.libsdl.org/SDL
    

    now go into the downloaded SDL directory and build & install (don't forget to install the dependencies mentioned above, before starting to compile) the libs by running:

    cd SDL
    ./configure
    make
    sudo make install
    

Don't forget to run:

sudo ldconfig

to update the necessary links and cache to the libraries.

Code::Blocks
Add to
Project > Build options > Compiler settings > Other options > -lSDL2

and to
Project > Build options > Linker settings > Other linker options -lSDL2

Remember to add these to the Project options and not only to Debug or Release settings. Also, if you've already wrongly compiled the sources, remember to Rebuild it (CTRL + F11)

Zanna
  • 69,223
  • 56
  • 216
  • 327
PeppeDAlterio
  • 5,642
  • 1
  • 15
  • 10
  • First of all, thanks for the great answer! All the commands work so well together. I use codeblocks, and it is not detecting the libraries. What are the changes that I need to make in my Codeblocks environment so that I can use these libraries? – progammer Sep 12 '13 at 08:07
  • New project-> SDL Project – PeppeDAlterio Sep 12 '13 at 08:19
  • It still shows the error, "fatal error: SDL/SDL.h: No such file or directory", when compiled. For the previous SDL version (I installed it using Synaptic Package manager), I had to add these in the Linker options: `sdl-config --cflags --libs` -lSDL_image, for the above error to be gone. What is to be done in this scenario? – progammer Sep 12 '13 at 08:31
  • 1
    You can compile it using gcc by adding -lSDL2 to gcc. For example: `gcc source.c -lSDL2`. I don't know how to do this with codeblocks, but I'm downloading codeblocks and I'll try and let you know. – PeppeDAlterio Sep 12 '13 at 09:04
  • I found out how to compile add these flags from codeblocks. I'm gonna edit my answer on how to do this. – PeppeDAlterio Sep 12 '13 at 09:13
  • 1
    Btw, it's ***SDL2/SDL.h*** NOT SDL/SDL.h – PeppeDAlterio Sep 12 '13 at 09:21
  • The answer is just PERFECT with respect to SDL dev libraries, which infact was my actual need at this time. But, how did you know what are all the dependencies that were to be installed and other details(dev library specific or otherwise also). Because expecting a reply to all the minute details is not fair on my part and also it would make the answer insanely large, can you suggest me some link which contains material to read over, which can help beginners understand this topic from basics. – progammer Sep 12 '13 at 09:40
  • The 'build-essential' it's a meta-package, as you can read here: https://help.ubuntu.com/community/MetaPackages too, meta-packages packages do not contain actual software, they simply depend on other packages to be installed. In this case packages needed to compile C/C++ sources. The other SDL2 dependencies, I took them from the internet. The "installation procedure" it's always the same in Linux. There is the configure script which makes the Makefile that you will use to make (compile) and make install (install) the program (there's always a README file included which tells how to use this) – PeppeDAlterio Sep 12 '13 at 10:01
  • 1
    Anyway you can check the Ubuntu Wiki for tons of useful guides: https://help.ubuntu.com/community and also this lin for general linux guides: https://help.ubuntu.com/community/ExternalGuides – PeppeDAlterio Sep 12 '13 at 10:08
  • `gcc -Wall -o module.out module.c $(pkg-config --cflags --libs sdl2)` also works the same way as with `-lSDL2` – progammer Sep 15 '13 at 10:26
  • Debian-based systems (including Ubuntu) can simply do "sudo apt-get install libsdl2-2.0" to get the library installed system-wide, and all sorts of other useful dependencies, too. "sudo apt-get install libsdl2-dev" will install everything necessary to build programs that use SDL (https://wiki.libsdl.org/Installation) – Dr.jacky Nov 30 '15 at 11:05
  • @PeppeDAlterio Where did it installed? "dpkg -L sdl2" says "package 'sdl2' is not installed". – Dr.jacky Dec 19 '15 at 06:56
11

You can also do:

If you just want the libraries:

sudo apt-get install libsdl2-2.0

If you want to do development:

sudo apt-get install libsdl2-dev
RandomUser762
  • 326
  • 4
  • 4