Author Topic: Installing SDL 2.0.5 on Ubuntu 16.04  (Read 859 times)

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4034
Installing SDL 2.0.5 on Ubuntu 16.04
« on: July 22, 2017, 01:05:20 AM »
For anyone who wants to know how to install SDL 2.0.5 on Ubuntu 16.04:

Currently the most recent Ubuntu packaged version of SDL is 2.0.4, so I'll be doing a source install for 2.0.5. First you'll need to grab the source package from the SDL2 download page.

Note that additional SDL libraries have their own download page:
SDL_ttf
SDL_image
SDL_mixer
SDL_net
They also host source packages for dependencies:
https://www.libsdl.org/projects/

For SDL_mixer, I also needed to grab the SMPEG project source from above. Ubuntu has a packaged version of the SMPEG development library (libsmpeg-dev), but it's too old.

I'm only going to install SDL2, SDL2_ttf, SDL2_image, and SDL2_mixer. If you copy the URLs from the project pages, you can download the source packages all in one go with wget (space separated, not newlines):
Code: [Select]
wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.14.tar.gz https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.1.tar.gz https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.1.tar.gz https://www.libsdl.org/projects/smpeg/release/smpeg2-2.0.0.tar.gz

I also needed to install some development packages before compiling some of them. The needed development packages (including optional ones) were:

SDL2:
Code: [Select]
sudo apt install libesd0-dev

SDL2_image:
Code: [Select]
sudo apt install libwebp-dev libtiff-dev

SDL2_mixer:
Code: [Select]
sudo apt install libvorbis-dev libflac-dev libfluidsynth-dev libmodplug-dev

From there installing each package was basically the same. Just remember that SMPEG needs to be compiled and installed before SDL2_mixer is built.

To unpack, build, and install each package the process looks something like this (adjusting for package and folder name):
Code: [Select]
tar -zxvf SDL2-2.0.5.tar.gz
cd SDL2-2.0.5
./configure
make
sudo make install
cd ..


Of course, if you're feeling lazy, this can be automated a bit.

You can combine the ./configure, make, and sudo make install steps into one command:
Code: [Select]
./configure && make && sudo make install
The && is used to chain commands, but only if the previous command succeeded.

The tar command only accepts one archive at a time to unpack, but there is a workaround. To unpack all the archives in one command:
Code: [Select]
ls smpeg2*.tar.gz SDL2*.tar.gz | xargs -i tar -zxvf {}
The ls command will produce a list of the relevant source packages, and then pipe the filename list into xargs. The xargs command is used to run a command repeatedly, for each argument passed in. This will be each of the archive file names. The xargs -i option (equivalent to -I{}) will replace any occurrence of {} with each input string. What follows is the command to be run for each argument. Here we use the tar command to unpack the archive. The -zxvf are options to tar, where z means we're dealing with a gzip archive (.gz), x means to extract, v means verbose so each filename is printed as it is extracted, and f means an archive file name follows.

You can apply the xargs trick to compile each package too:
Code: [Select]
ls -d smpeg2*/ SDL2*/ | xargs -i bash -c "cd {} && ./configure && make && sudo make install"
A list of package folders is generated, piped into xargs, which then runs a sequence of commands in a new bash shell. The bash shell is used to run multiple commands at once within xargs (structured like: ls | xargs (cmd1, cmd2, cmd3)), as opposed to running just the first command with xargs, and then trying to run the remaining commands after xargs completes (structured as: (ls | xargs cmd1), cmd2, cmd3). It also has the handy benefit of restoring the current directory after each bash shell completes, so you don't need to worry about tracking the effects of cd {}.

As each build can take a while, your sudo password might time out, causing you to be prompted to enter it again for each sudo make install command. This of course halts the build while it waits for your input. Instead, you can split the sudo step for later so this doesn't happen:
Code: [Select]
ls -d smpeg2*/ SDL2*/ | xargs -i bash -c "cd {} && ./configure && make"
ls -d smpeg2*/ SDL2*/ | xargs -i bash -c "cd {} && sudo make install"


All together, that becomes:
Code: [Select]
# Install ubuntu dependencies
sudo apt install libwebp-dev libtiff-dev
sudo apt install libvorbis-dev libflac-dev libfluidsynth-dev libmodplug-dev

# Download source archives
wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.14.tar.gz https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.1.tar.gz https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.1.tar.gz https://www.libsdl.org/projects/smpeg/release/smpeg2-2.0.0.tar.gz

# Unpack archives
ls smpeg2*.tar.gz SDL2*.tar.gz | xargs -i tar -zxvf {}

# Compile packages
ls -d smpeg2*/ SDL2*/ | xargs -i bash -c "cd {} && ./configure && make"
# Install packages
ls -d smpeg2*/ SDL2*/ | xargs -i bash -c "cd {} && sudo make install"
« Last Edit: July 24, 2017, 12:37:13 AM by Hooman »

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 1645
    • LairWorks Entertainment
Re: Installing SDL 2.0.5 on Ubuntu 16.04
« Reply #1 on: July 22, 2017, 03:33:40 AM »
There's at least one benefit to developing on Windows -- SDL 2.0.5 binaries have been available in GCC/MSVC since the day it was released.  :D
« Last Edit: July 22, 2017, 03:44:09 AM by leeor_net »
- Leeor
LairWorks Entertainment

Titanum UFO's

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4034
Re: Installing SDL 2.0.5 on Ubuntu 16.04
« Reply #2 on: July 22, 2017, 10:55:04 AM »
Linux package lag times are admittedly often quite horrible.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4034
Re: Installing SDL 2.0.5 on Ubuntu 16.04
« Reply #3 on: July 24, 2017, 10:41:51 AM »
Discovered a few errors/omissions while verifying some of the above. Seems a missed a warning about a missing library, and forgot about one manual fixup I did. Once I've finished verifying, and have a proper automated set of steps, I'll update the above article. For now, here's the errors I've noticed.

The main SDL2 packaged was giving a warning in the configure script until I installed an additional development dependency: libesd0-dev

For the main SDL2 package, I was getting a link error due to an undefined reference to the 'mir_output_get_current_mode' function from the "mirclient" library. To get around this, I modified the Makefile (after running the configure script), and modified the EXTRA_LDFLAGS variable to add " -lmirclient" at the end.

There's probably a better way to fix that. In particular, it'd be nice to patch something up before running the configure script, as the configure script outputs the Makefile. My knowledge of autotools and configure is somewhat limited though. I figure I'll do a bit of reading on that and see what I can come up with.

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 1645
    • LairWorks Entertainment
Re: Installing SDL 2.0.5 on Ubuntu 16.04
« Reply #4 on: July 24, 2017, 01:23:51 PM »
You should consider submitting this to Ubuntu for inclusion with their apt package get or whatever it's called.

I'll link to this post in the OPHD developer notes for Linux developers.
- Leeor
LairWorks Entertainment

Titanum UFO's

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4034
Re: Installing SDL 2.0.5 on Ubuntu 16.04
« Reply #5 on: July 25, 2017, 04:41:17 AM »
Heh, funny you should say that. I did recently dig up an Ubuntu packaging guide.


As for the mirclient thing, I found you can disable use of dynamic loading for mirclient with the configure script, which will cause the appropriate -lmirclient flag to be added when linking:
Code: [Select]
./configure --enable-mir-shared=no

This has me wondering what's wrong with the dynamic loading for mirclient. Many other libraries are set to be dynamically loaded if present. Why does only this one end up causing a link error?

More reading ahead. Finally starting to understand some of this autotools stuff.
« Last Edit: August 05, 2017, 04:01:08 AM by Hooman »

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4034
Re: Installing SDL 2.0.5 on Ubuntu 16.04
« Reply #6 on: August 05, 2017, 04:25:36 PM »
Some additional info on the mirclient issue:

Here's a relevant StackOverflow question: Build error for SDL2-2.0.5 in Ubuntu 16.04
The relevant SDL2 Bugzilla entry: Bug 3539 - SDL2, missing MIR LDFLAGS
This bug was quickly patched in: changeset 10742

Since the problem has already been patched, I assume the changes will be rolled out in the 2.0.6 release. Speaking of which:
Last Call for 2.0.6 Bugs
The thread was started a little over 2 months ago, and has ongoing discussions up to present. Hopefully a new release will be out soon.

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 1645
    • LairWorks Entertainment
Re: Installing SDL 2.0.5 on Ubuntu 16.04
« Reply #7 on: August 05, 2017, 07:04:31 PM »
Welp, once 2.0.6 goes out I'll likely upgrade.
- Leeor
LairWorks Entertainment

Titanum UFO's