Dependencies question

Archives Forums/Linux Discussion/Dependencies question

SLotman(Posted 2009) [#1]
I tried running my game on a Linux distro, but after double-clicking the executable, nothing happened.

Then, I went ran it from a terminal, which complained about some missing libraries. I started googling about it, and learnt about libs dependencies on Linux, and used the ldd command to get all the dependencies from my game:

slotman@ubuntu:/media/disk/Dete# ldd ./detelinux
	linux-gate.so.1 =>  (0xb7f60000)
	libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0xb7ec1000)
	libGL.so.1 => /usr/lib/libGL.so.1 (0xb7e33000)
	libGLU.so.1 => /usr/lib/libGLU.so.1 (0xb7dc1000)
	libX11.so.6 => /usr/lib/libX11.so.6 (0xb7cd2000)
	libXxf86vm.so.1 => /usr/lib/libXxf86vm.so.1 (0xb7ccc000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7bde000)
	libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7bb8000)
	libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7ba9000)
	libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7b8f000)
	libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7a31000)
	libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7a2d000)
	libz.so.1 => /usr/lib/libz.so.1 (0xb7a17000)
	libXext.so.6 => /usr/lib/libXext.so.6 (0xb7a08000)
	libxcb-xlib.so.0 => /usr/lib/libxcb-xlib.so.0 (0xb7a04000)
	libxcb.so.1 => /usr/lib/libxcb.so.1 (0xb79eb000)
	/lib/ld-linux.so.2 (0xb7f46000)
	libXau.so.6 => /usr/lib/libXau.so.6 (0xb79e8000)
	libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0xb79e3000)


My question is: if I manually include those libraries in the same path as my game, will it work without the user having to install them?

Is there an application "Molebox like" for Linux that can take an executable and "statically link" all those libraries?

If not, what can I do besides recommending the user to apt-get everything on that list?

Btw: I found a pretty nice installer for Linux, called InstallJammer: http://www.installjammer.com/


Jim Teeuwen(Posted 2009) [#2]
Those packages will have to be installed system wide, which likely means they require the use of a package manager. Normally .deb or .rpm packages already take care of those dependencies for you, but in this case you will have to make sure your game's installer handles it.

It's possibly not very difficult to have your own install script run the above 'ldd' command and just parse the output into something that checks whether the listed packages exist or not.. then pass them to system's package manager for installation. The package manager will take care of any further dependencies.

Something like this (pseudo code install.sh):
for each pkg in (ldd /path/to/mygame/binary)
   if pkg does not exist
     package_manager install pkg
   end if
next



SLotman(Posted 2009) [#3]
Unfortunately that is way beyond my Linux capabilities right now :(

I don't know even how to relate libraries like libXdmcp.so.6 (just an example) to whatever name apt-get should use to download the necessary files :/


Jim Teeuwen(Posted 2009) [#4]
Well, i've been playing around with it a little and unfortunately it looks like it's not gonna be that easy.

Missing dependencies are usually left to the user's discretion, unless you hand out your program in a .deb or .rpm package.. These packages can be configured to automatically sort out all the required libraries a user needs.

They won't work on all linux versions though, because many use different package managers and thus require different types of packages. .deb is for Debian based systems.. .rpm for RedHat systems etc. And then there are those versions of linux who don't have package managers at all.

If you plan to distribute your app to other users, your best bet is to write down a list of the libraries it uses on your own system and supply this list with your application. The user can then decide what he should do with the information.

Unfortunately this is one of those situations where linux still has a lot to learn. Diversity is all well and good, but this kind of stuff only serves to cripple it and drive people away from linux. The upside is that those who stick with linux are likely skilled enough to know what to do to make your program run.


SLotman(Posted 2009) [#5]
Thank you so much for your replies.

I decided to do exactly that - I'm going to list all the dependencies and let the user decide what to do.

Specially because my game is going to be installed in public schools, I and have no clue what distro those computers will have. I just wish there were something easier on the user - who knows if those systems are maintained by someone with knowledge, or people will just try to "guess" how things works :P

I just find it funny - got tired of hearing Linux users over the years laughing about the "DLL hell" from Windows... but that situation looks exactly like the same thing!


dawlane(Posted 2009) [#6]
If you've ever used Pure Basic on linux there is a script that checks to see if the system has the necessary packages installed.

In a shell script You would use one of the following commands....
Which  ...... to locate a command
ls     ...... to list directory contents (can be used to locate a file :))
pkg-config ...... returns information about installed libraries

to find out more on these in the terminal type: man command name

You would use each command something like this
which gcc >/dev/null                      ....  find gcc 
ls /usr/lib/libstdc++.so.* >/dev/null     ....  find libstdc++ 
pkg-config --cflags gtk+-2.0 >/dev/null   ....  find an installed package 

After each command you will need to check the result with something like this
if [ $? -ne 0 ]; then
   echo "what your looking for isn't here"
   exit 1
fi


Any script written that is to be deployed to another machine will have to have it's execute permission set. You could do this by telling them how to use the chmod command or using the file manager and right-click to get the scripts properties dialog.

Here are two sites that may be of help with writing sh/bash scripts
http://www.freeos.com/guides/lsst/
http://steve-parker.org/sh/sh.shtml


Jim Teeuwen(Posted 2009) [#7]
@dawlane:

Once you know the actual package names for each distro/package manager out there, then yes, installing it all through a simple script will be easy.

I'm working on an Install script fpr Blitzmax itself which faces much the same issues. I posted the latest version of it in this thread: http://www.blitzbasic.com/Community/posts.php?topic=84073

However, as you can see in that thread also, getting to the point where you find those package names is not as straight forward as it seems.

The problem SLotman faces is the same as in the install.sh thread. Package names are different for every package manager out there and some linux distros don't have package managers at all. There really is no automated way of discovering all these dependencies accurately, so you are left to maintaining a list of these manually and just let the user decide how to solve the problem.

This is also likely why most of the linux software out there is targeted at specific distros/package managers (Aptitude, Yum, URPMI, PacMan, Emerge, etc). And support for different distros is handled by building the app into distinctly separate packages. There is no single "1 size fits all" solution that automatically takes care of all dependency resolutions for you.

Having said that, by offering support for the main package managers Aptitude, Yum, URPMI, PacMan and Emerge, will make your app compatible with a massive list of linux distros in 1 go, since most of them are forks of some existing system like Debian or Red Hat and will therefor use the same package management utilities.