Geek / Technical Linux Game Development

Distributing Binaries: G++, libstdc++, and Static Linking

I’ve been asking certain Gnu/Linux-using friends to test out Oracle’s Eye while I work on it. I’ve already found that I need to specify SDL_image as a requirement because of such testing; however, I don’t want to have to send an 8MB source package that contains mostly useless-for-the-tester code or binary data. Asking someone to get such a huge download and build a project themselves just to check it out or test it is asking too much, I think.

Since they don’t need the source to test it, I can just put together the binary files I need and send them together in a tar.gz or zip file. Or so I thought.

I stumbled upon one of the things that developers face when they are new to Gnu/Linux: shared libraries that prevent distribution of your binary files. When you distribute the source and expect people to build it usually isn’t a problem, but I don’t anticipate all of my end users being proud geeks who wouldn’t mind spending hours getting my game to work again when it was working perfectly fine previously.

I have two Gnu/Linux systems, one which runs Debian Testing, with a 2.6 kernel and GCC 4.0.2, and the other which runs Debian Stable, a 2.4 kernel, and GCC 3.3. I don’t update the latter often because I use it as a backup machine. I don’t want to accidentally introduce incompatibilities that would prevent it from working properly.

When I brought my “release” over to the other machine and tried to run it, I got the following:

./oracleseye: error while loading shared libraries: cannot open shared object file: No such file or directory

Let me just say that searching for solutions to this issue is difficult. You get a lot of results that aren’t relevant. Or I did, anyway. And I knew it had to be possible. Quake 3 Arena works fine, and I’ve upgraded libstdc++ a number of times, so why can’t my own code work so nicely?

So I asked on IRC, but people who leave their clients running all day even if they aren’t there are not too helpful. I searched some more, posted a question, but then found the possible solution immediately after the post.

Linking libstdc++ Statically by Johan Petersson talks about the exact problem I am having and offers a solution that is easy and seems elegant.

Basically, you need to statically link to both libstdc++ AND libgcc. GCC won’t let you do one without the other. And so far it seems to work.

I managed to get my code to run on my main system, my backup system, and my work system, and I no longer have to recompile on each. It only adds 0.5MB to my download, and I may even get better results once I stop using the debug build options. I’m not sure if there is a “better” solution, but I’m pretty happy for now. Thanks, Johan!