Making my program portable

Hi, guys! I’m completely new to SDL. I’ve heard about it many times, but it’s the first time I’m actually trying to use it.

Here’s my concern. I haven’t used SDL before because I don’t like my programs to have dependencies. I program mainly for GNU/Linux, but would like my programs to be easy to compile for other platforms (mainly Windows). But I don’t want a user to have to install anything else when they want to run my program. I want it to be portable, so they just copy the files to a directory and run it and no dependency is missing.

I have read in the Wiki that static linking is possible, but not recommended. Even I tried to do it and couldn’t get to accomplish it, so if it’s hard and also not recommended, I wonder what the correct way to get what I want is.

Can you guys point me in the right direction? Thank you very much!

You say files (plural) so I assume that you are not averse to distributing SDL2 with your program as a DLL (on Windows) or a Framework (on MacOS) etc. In that case there is no need for static linking to remove dependencies; that would only be required if you want to distribute your program as a single executable file.

Hi! Thanks for your reply. Indeed, I’ve no problem with including SDL as a separate file with my program. Of course, I would prefer it linked; it’d look more professional; but it’s not very important to me. I don’t use Mac and Windows is only a system I would like to be able to compile for. My main concern is about GNU/Linux. Can I just include the .so file with my program and it’ll work? And I mean… not just that that my program will have SDL there, but also, SDL won’t require any extra dependencies of its own.

Mostly, yes, assuming you’ve linked your app correctly. I don’t think SDL links to anything that wouldn’t be standard on a Linux system. It’s not even linked directly to OpenGL, instead it finds and loads OpenGL on its own if it’s needed.

Have you tried looking at AppImage for distributing Linux builds of your app? It’s a toolset that bundles your app into a single file, an executable with a SquashFS filesystem embedded into it that contains any libraries or other files your application needs.

Many Linux distributions come with SDL2 pre-installed so you may not need to do anything.

Can I just include the .so file with my program and it’ll work?

You’ll also have to set RPATH $ORIGIN when linking your executable to make it look for the SDL2 .so in its own directory

And I mean… not just that that my program will have SDL there, but also, SDL won’t require any extra dependencies of its own.

SDL does need a few libs to talk to the system, but

  1. Those really should be installed already on a working desktop system
  2. Those are also needed when linking SDL2 statically

Hi
It is not a good idea but maybe try Create your first snap | Ubuntu

I’m familiar with AppImage. Although I have never been able to make my own (I get lost in the instructions; I’ll guess I have to try again), it does sound like a very good option.

I’ve been reading about RPATH. The thing is truly complex. I’ll have to make many tests. Can I compile the whole of SDL in a single .so file or does it come in pieces and then I include the ones required for the functions I will use? Or it comes all split up, but I still need to include all of them?

The things that should already be installed on my system, you mean, for example, XLib and company? XLib, I know to be almost guaranteed to be installed. Not the development part, so to compile, it’d be necessary to install more, but that’s OK. I’m fine with people having to install other libraries to compile my program as long as they don’t have to do it to run it.