We have moved to a new Sailfish OS Forum. Please start new discussions there.

Porting SDL 2.0 game to Sailfish

asked 2014-02-01 11:38:52 +0300

pellen gravatar image

updated 2014-02-03 14:08:08 +0300

thp gravatar image

I have a very simple open-source turn-based game I wrote recently that can compile (using cmake) at least in Ubuntu and probably many other desktop OSs as well. Now I thought it would be fun to also compile it for my Jolla phone, but not sure where to start. The game uses SDL 2.0, and I stumbled upon a page claiming Sailfish already supports that (https://sailfishos.org/wiki/Porting/Harmattan), but I can't find any information about how I would (cross-)compile it for the Jolla phone. Do I have to wrap it in a Qt5 app somehow, or can I configure cmake to just build it from the command-line (inside of that Mer virtual machine I guess?)?

edit retag flag offensive close delete

4 Answers

Sort by » oldest newest most voted

answered 2014-02-01 13:50:34 +0300

Kontio gravatar image

updated 2015-03-03 19:17:17 +0300

SDL 2.0 is available on the device. No need to wrap it into a Qt5 app, but you have to do all by hand (cross compiling, rpm packaging etc). I can't give you here a step by step how to, but some pointers which hopefully help.

The Mer Platform SDKwith a Sailfish OS target provides easy tools, to cross compile your application. You don't need to set up and configure that your self, you can get that in a Virtual Box environment for free from the Sailfish OS SDK. So go to https://sailfishos.org/ and download the the Sailfish SDK and install it.

Just to test that all is working you could go through these steps (optional).

You don't need the Qt Creator any longer. Just ensure the "MerSDK" Virtual Box machine is running, since the cross compilation is done inside the Virtual Box. You can start it from the Oracle VM VirtualBox Manager.

You can run the compile commands through the Virtual Box window. Or what I would recommend, you log in via ssh to the build engine to run the compile commands. See the question How do I login into the emulator or build engine? resp. the answer to how to login to the Build Engine. Login as user mersdk.

The sb2 command and it's helper tools sb2-* are the tool used to do the cross compilation. The Mer wiki has a nice introduction to sb2. In the Build Engine the available sb2 targets are:

$ sb2-config -l

The SailfishOS-armv7hl target is used to build binaries for the device, the SailfishOS-i486-x86 target can be used for Sailfish OS Emulator Virtual Boxes. So for any sb2 commands you run, use the option -t to tell sb2 with which target you want to operate.

sb2 -t SailfishOS-armv7hl .....

With sb2-config -d SailfishOS-armv7hl you can configure SailfishOS-armv7hl to be the default target. So you don't need to provide the -t option.

The SailfishOS-armv7hl target has the SDL headers or cmake not pre installed. Search for the SDL2 devel packages:

sb2 -t SailfishOS-armv7hl -m sdk-install -R zypper search sdl cmake

And install the needed packages:

sb2 -t SailfishOS-armv7hl -m sdk-install -R zypper install SDL2-devel cmake

Your project might need other SDL2-*-devel packages or headers files. Search and install them the same way.

Now you can start compiling, use the cmake command as usual, just put sb2 -t SailfishOS-armv7hl always in front of it.

To create an RPM package, you need a .spec file. If you have done these steps, you get a good base to start from. Replace the qmake commands with your cmake commands. To build the RPM you can use the mb2 tool (it needs the same -t option as sb2):

mb2 -t SailfishOS-armv7hl -s path/to/my_sdl_project.spec build

If all goes well you have an RPM package. If you want to submit it to Harbour, you have to ensure it's packaged correctly (see also the Harbour FAQs). Use the rpmvalidation.sh command to verify, if the RPM can be accepted.

Update: 03. March 2015 SDL2 apps are now allowed in Harbour, updated the text accordingly.

edit flag offensive delete publish link more


Thank you! That would have taken forever to figure out on my own. I now have a binary. Unfortunately I guess I will have to figure out how to statically link it to SDL2 before it can actually run, but this is a huge step forward and I didn't think it would be so easy to get even this far.

pellen ( 2014-02-01 23:07:28 +0300 )edit

Actually if SDL 2.0 is on the device I guess I should be able to link dynamically already, but there is no SDL on my phone, so I guess that is the problem to solve (eg update to latest Sailfish?) rather than static linking.

pellen ( 2014-02-01 23:12:21 +0300 )edit

yes SDL is not pre installed on the phone either. But you can install it and can use it dynamically. You can do that on the device as user nemo with:

pkcon install SDL2

do the same for the other SDL2_* packages, you need (e.g. SDL2_image).

Kontio ( 2014-02-02 11:24:17 +0300 )edit

I am windows environment programmer so I'm not comfortable working with command line, can all these be done from inside the IDE?

hamlatzis ( 2014-02-18 12:16:44 +0300 )edit

answered 2014-02-03 14:11:12 +0300

thp gravatar image

updated 2015-03-03 19:19:15 +0300

Kontio gravatar image

Update: 03. March 2015 SDL2 apps are now allowed in Harbour!

Sailfish OS added SDL 2.0.1 (upstream Git with QtWayland changes that are already upstreamed, and will probably be part of SDL 2.0.2 or what the next SDL2 release will be) to the repositories. Earlier Sailfish OS releases have an earlier version of SDL2 based on a Git snapshot before the 2.0.0 release, with Wayland patches.

In order to support the new SDL2 version in Harbour there still have to be some backend changes to the store to handle apps that are only installable starting from a given OS release (otherwise SDL2-based applications might be broken for all users running a software version before Sailfish OS, even though older releases do have a pre-2.0.0 version of SDL2).

Once that is in place, you will be able to use SDL2 in Harbour. Until then, you can now conveniently install SDL2 on your device without needing to add additional repositories. Apps published through non-Harbour means can already work today.

You can watch sdk-harbour-rpmvalidator #21 for when this change will be merged.

edit flag offensive delete publish link more


Since Sailfish OS has support for the SDL2 family libraries since version and now we are in version WHY aren't we allowed to submit games based on SDL2?

hamlatzis ( 2014-04-19 13:26:21 +0300 )edit

Do I read that link correctly that it still is waiting to be merged? Will SDL be officially supported in some OS update, or is it more of an Jolla store application update that is needed?

pellen ( 2014-09-12 23:10:06 +0300 )edit

@pellen yes you read correct it's still bending, and also depends on the multi version support in store, see also this answer

Kontio ( 2014-09-15 11:14:59 +0300 )edit

answered 2014-02-19 16:13:31 +0300

thp gravatar image

Here's a small example project that shows how to set up a custom project build in Qt Creator and hook it up to the build engine. Building and deploying works fine (tested under OS X and Linux, if you have problems on Windows, let me know):


You have to do some manual setup steps when you initially load the project into Qt Creator, and debugging might not work out of the box.

Let me know if that works for now or if you get stuck somewhere.

edit flag offensive delete publish link more

answered 2014-02-18 21:16:48 +0300

hamlatzis gravatar image

This isn't acceptable answer. First of all I shouldn't have to compile/link/package everything using command line since THEY (jolla) give an IDE. It's 2014 I should be able to use and IDE, to set my breakpoints, trace my code etc. If they don't want us to use an IDE then during installation they shouldn't have provided one.

I am a professional c/c++ developer with 12 years on my back. I have been developing for the past 4 years (give or take) for various mobile platforms (Samsung's badaOS, HP's webOS, RIM's PlayBook and BB10, Apple's iOS) I've never has such a problem. All my apps and games are source compatible and depending on the IDE I use I create different binaries/packages for the above platforms. I was even able to have one of my games compile for Android using java and c/c++ (again common source files) through jni and now jolla requires me to return to stone age and compile everything using command line? wtf?

Regarding SDL2 I don't think there should be a problem since THEY (jolla) give guidelines on how to use SDL2, if they didn't want us to use SDL2 then they shouldn't give guidelines. Besides if you ssh into the developer image and type "zypper se sdl" you'll see that every SDL2 library is installed (the ones I use are SDL2, SDL2_image, SDL2_ttf, SDL2_mixer).

Check my blog to see my games on various mobile platforms. http://7cecdab4.blogspot.gr/

edit flag offensive delete publish link more


The problem, I suppose, is that the IDE is called QtCreator, and SDL isn't Qt. Installing the SDL packages into the build engine can be done from the IDE, so you don't have to run the sdk-install commands from the command line. That just leaves actually building, but I'm not really sure if anyone has managed to get QtCreator to use the Mer build engine to build something that doesn't use qmake. Perhaps it's possible, you could always try. I've mostly just used command line myself.

ovekaaven ( 2014-02-19 03:12:03 +0300 )edit

Please do not use the answer feature for comments. Use comments for it. Thanks. The question is specific about an exiting SDL2 project using cmake. Even Qt Creator has some support for cmake, the Sailfish OS SDK does not support it. So I gave an answer which I knew would work with cmake. A qmake project w/o using Qt but using SDL libraries I would expect to work fine with Qt Creator the GUI/IDE way, but I didn't test it myself. Using CLI might still be easier than to change to qmake in some cases.

Kontio ( 2014-02-19 11:16:37 +0300 )edit

I've compiled cmake projects in the SDKs version of QtCreator, do not remeber the exact steps but it's was not much more than opening the project and compile. No big problems. (Trying hard to ignore stupid comments about command line and the stone age)

evk ( 2014-02-19 11:58:44 +0300 )edit

@evk: yes if you want for desktop everything is ok, but not for the kits supplied by jolla.

Thaodan ( 2015-05-21 18:16:37 +0300 )edit
Login/Signup to Answer

Question tools



Asked: 2014-02-01 11:38:52 +0300

Seen: 4,626 times

Last updated: Mar 03 '15