[HELP ME PLEASE] error while loading shared libraries: libSDL2-2.0.so.0

I’m trying to run my game on another PC with the same distro of mine. But it returns me this following error:

error while loading shared libraries: libSDL2-2.0.so.0: cannot open object file: no such file or directory

To compile I use this command (on QtCreator, to be more specific):

g++ -Wl,-rpath,/home/daniel/Qt/5.11.1/gcc_64/lib -o untitled main.o Entity.o Game.o GamePanel.o GameSolids.o MainThread.o Player.o TextureManager.o Level.o Stage.o Enemy.o EnemiesManager.o GlobalConstants.o -lX11 -L/home/daniel/QtProjects/untitled/…/…/…/…/usr/lib/x86_64-linux-gnu/ -lSDL2 -lSDL2_image -lGL -lSDL2-2.0 -lSDL2main -L/home/daniel/Qt/5.11.1/gcc_64/lib -lQt5Core -lpthread

That is, in my PC the game runs because the libraries are installed, but I don’t want the user needs to install additional libraries to run the game, I want the libraries goes together with the game. How can I do it?

I was reading about static libraries but, until then, I think I was using it on that command I wrote. It would be like a .dll arquives on Windows. Would this be the solution?

My SO is Linux Ubuntu 18.

Anyway, Thanks.

There are several solutions. Some that come to my mind:

  1. Package your game in proper packages, i.e. rpm and deb respectively.
    In that package you can list your games dependencies and the package
    manager will install them when needed and uninstall them when no longer
    needed. This has the advantage that you will be using the OS version of
    the package with the most recent security updates. It has the
    disadvantage that you are not guaranteed a specific version which can
    be a problem with libraries that like to introduce incompatible
    changes. But SDL should be fine in that regard.

  2. Install a copy of the library in question together with your game
    and start your game via a shell script that uses LD_LIBRARY_PATH. To
    see what that looks like, check out the official Ubuntu packages of
    Google Chrome (https://www.google.com/chrome/). The starter script
    is /opt/google/chrome/google-chrome. BTW, “/opt/something” is also the
    place where your installer should install your game if it is not
    properly packaged according to 1.

  3. static libraries

static linking can be a bit hairy and is rarely a good choice, so I’m
not describing how to do it here. The other 2 options are simply
superior in all but the most exceptional cases.