Caveat: This isn't a total solution but some suggestions and is prefaced by top comment's and comments under OP's [now deleted] answer.
To review ...
After fixing the original issue by use of:
gcc -o SDLGAME SDLGAME.c `pkg-config --cflags --libs sdl2`
OP running the program produces:
error: XDG_RUNTIME_DIR not set in the environment.
This may be a general issue about the ubuntu install itself. Some resources for that: https://askubuntu.com/questions/872792/what-is-xdg-runtime-dir and
https://askubuntu.com/questions/456689/error-xdg-runtime-dir-not-set-in-the-environment-when-attempting-to-run-naut
A workaround may be:
export XDG_RUNTIME_DIR=/tmp/dir
mkdir -p /tmp/dir
But, I ran the program successfully on my home system, running fedora 29 and my ubuntu system running 18.04.5
On my systems, XDG_RUNTIME_DIR
was set to /run/user/1000
. However, with/without the workaround and even doing unset XDG_RUNTIME_DIR
worked on my systems.
However: On my ubuntu system, I had removed the standard libsdl2
package and rebuilt and installed it from the source package a year ago due to some issues I had.
So, if the workaround doesn't work, I recommend libsdl2
rebuild/reinstall from source.
Even if the standard package is working, when debugging your app, it can be helpful to be able to consult the libsdl2
source.
Note that one change I made to your app was to add a sleep(3)
at the bottom so you can see the window come up.
Here is the method I used to build/install from source:
It's probably necessary to uninstall/remove the binary libsdl2
package. So, you'll have to do (e.g.)
sudo apt-get remove libsdl2 libsdl2-dev
Or, whatever the binary package is called [I forget]. But, those also came from: apt-cache search libsdl2
So, once that's cleaned out, what I did was:
- Create a directory (e.g.):
$HOME/aptsrc
cd $HOME/aptsrc
- Download the source package [without
sudo
]: apt-get source libsdl2
- This extracts several files (e.g.
*.tar.gz
, *.tar.xz
, *.dsc
and a directory. On my system, it was: libsdl2-2.0.8+dfsg1
, but for you it may be different. Do (e.g.): DIR=$HOME/aptsrc/libsdl2-2.0.8+dfsg1
cd $DIR
- Configure with:
$DIR/configure
- Run cmake:
cmake $DIR
- Run make with:
make
- Install with:
sudo make install
Note that this comes from an internal script I created. Even after the cd $DIR
, I think it's necessary to use full path on the commands [where indicated].
Now, the library should be installed under /usr/local
. The output of pkg-config --cflags --libs sdl2
should reflect this:
-D_REENTRANT -I/usr/local/include/SDL2 -L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,--enable-new-dtags -lSDL2
The original output of this command would have looked like:
-I/usr/include/SDL2 -D_REENTRANT -lSDL2
This is for the standard install from the binary package, so if you still have that, the binary package may still be installed.
Otherwise, you should now be able to rebuild your app using the original gcc
command. Now, it should be attached to the source built version of the library. You can confirm this with: ldd ./SDLGAME
but just running it might be easier.