Linux static linking

Feb 1, 2009 at 6:20pm
Ok this is not related directly with programming, but however it is an important part.

Most of times dinamic link is the better choose (and works fine).

But, in linux, a binary cannot be read in more machines and must be rebuilded by user every time.

I often do programs that requires allegro. Allegro can be difficult to install in some linux distros (i have no problem to install Allegro by sources in Ubuntu, but I had problems elsewere) so I am thinking to release also a static linked version of a program I have published.

Using Allegro static link script `allegro-config --static --libs release` a lot of libraries remained shared (so you must have the exact version of the same shared libraries) and it is useless.

I tried to link staticly also the other libs but I had problems.

if I launch

g++ -o bin main.o -static `allegro-config --static --libs release`
I have A LOT of errors (seems that .a libraries <static libs> requires .so version <dynamic libs> (???) )

the same thing if I launch a very long command-line implementing manually all the libs

g++ -o bin main.o -nostdlib -nodefaultlibs -static -a/usr/lib/libXxf86vm.a -a/usr/lib/libXcursor.a .... `allegro-config --static --libs release`

Again... a LOT of errors like before (seems the same ones).

----

Anyone can expain me g++ static-link?
Feb 2, 2009 at 2:00am
Feb 3, 2009 at 7:18pm
But, in linux, a binary cannot be read in more machines and must be rebuilded by user every time.


Not technically true. This depends on the versions of libraries it's linked against and what's installed on your PC. It's possible to distribute a dynamically-linked executable, as long as the target platform has the same libraries your using.
Feb 3, 2009 at 8:36pm
glibc, I've read, is a particularly nasty library, changing in incompatible ways even between minor versions.
Feb 4, 2009 at 6:24pm
Another option to create from dynamically linked executable self-contained one one is Ermine
http://magicErmine.com

Ermine is commercial, but it's behaves a lot better than statifier on systems with memory randomization.
Feb 5, 2009 at 11:29pm
But, in linux, a binary cannot be read in more machines and must be rebuilded by user every time.
Not technically true. This depends on the versions of libraries it's linked against and what's installed on your PC. It's possible to distribute a dynamically-linked executable, as long as the target platform has the same libraries your using.

Yes I know it. But you must have the SAME libraries and the SAME VERSIONS of libraries (nor older, nor newer). And I don't think it is possible simply to redist .so libaries........... So in 99% of cases you have to rebuild a dynimic-linked program from source (or, at least, from object codes... but it is the same thing becouse depencies are resolved in the linking phase).

--------

Statifier is not a solution: it is a beta (version 0) and it is installable only into system by source (I have a ubuntu). This means that I have to run configure and make install. This can be not a problem, but if I want to remove it in a second time, I don't know how to do it, so I decided to don't install it.

About Ermine... I'll probably see it (but I don't want to pay a program :P).

But, however, any one knows why those problems occurs? (it is impossible to me to see ALL the warning, but I can post the piece I can see if you need it).
Last edited on Feb 5, 2009 at 11:30pm
Topic archived. No new replies allowed.