PDA

View Full Version : Statically Linking... everything



bpetty
24th October 2006, 21:22
I have question about statically linking libraries into your application under linux.
I have a binary I am trying to distribute under linux and it is not going well.

So my basic questions are:
1. How do I statically link in libraries like:
libdl.so.2 => /lib/libdl.so.2 (0x40031000)
libc.so.6 => /lib/i686/libc.so.6 (0x42000000)
libm.so.6 => /lib/i686/libm.so.6 (0x40035000)
libpthread.so.0 => /lib/i686/libpthread.so.0 (0x40057000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

2. I added Xinerama support along with all the others. How do I turn that off with out reconfiguring my Qt source. There has to be a way to tell it not to use them in the .pro file or something.

3. By not having these libraries... will that make my application look / act different? I also noticed Qt said they have their own versions... should I use those if they do actually effect my application?

I know that if I add "CONFIG += static" to my .pro file it will link Qt libraries statically... I am not worried about those. Just the others.

Here is a list of my lib. dependencies:
libpng12
libSM
libICE
libXrender
libXrandr
libXcursor
libXinerama
libfreetype
libfontconfig
libXext
libX11
libz
libglib-20
libdl
libpthread
libstdc++
libm
libgcc_s
libc
libXfixes
libexpat
/lib/ld-linux.so.2

I am getting a lot of libc.so.6 errors when I copy my app to another system.. and it doesn't work. Hopefully statically compiling it will. I also head that I should not statically link X11. If anyone has any advice... I am all ears.

jacek
24th October 2006, 21:42
Maybe this will help:
http://blogs.qtdeveloper.net/archives/2006/02/10/distributing-qt-based-binaries-on-linux/
http://blogs.qtdeveloper.net/archives/2006/05/09/deploying-qt-applications-on-linux/

bpetty
24th October 2006, 21:47
I have looked at those links before. I am compiling under Ubuntu.. I don't know if it supports LSB.

There has to be another way to get it to link those guys in statically. Should I just write a Makefile from scratch? Is that easier?

wysota
24th October 2006, 22:14
Basically, if you want to compile everything statically, you need a static version of each of the libraries you want linked statically. Then you need to adjust your project file, run qmake and make. Just make sure the linker can find all the static libs. Also be aware that statically linking some of the libraries (like libc) is very dangerous - the resulting binary may not be usable at all due to conflicts between two versions of libc, you'd have to link literally everything statically.

bpetty
26th October 2006, 16:58
I have talked to a few people from Troll Tech and I think I have a good solution.

I am going to try to compile it under linux using an older version of glibc... since I may want to support that.

So I am going to keep everything shared... Qt libraries. I am also going to reconfigure to always use Qts version if they have one... I noticed that option but I chose to use the native libraries before.

I guess my main question is this:

With the setup described above... what libraries should I statically link in? Like libICE? I heard that I should not statically link in X windows libs. The problem is that I don't know if I am using the functionality of some of these libraries. How does one try to trim down their dependencies?

wysota
26th October 2006, 17:43
If you are targeting LSB compliant distributions, you don't have to statically link anything that comes with LSB.


I have looked at those links before. I am compiling under Ubuntu.. I don't know if it supports LSB.

Try issuing a "lsb_release" command from a terminal. It should return something like this (the actual number may vary):
LSB Version: lsb-3.1-ia32:lsb-3.1-noarch:core-3.0-ia32:core-3.0-noarch:core-3.1-ia32:core-3.1-noarch:cxx-3.0-ia32:cxx-3.0-noarch:graphics-3.0-ia32:graphics-3.0-noarch:lsb-3.0-ia32:lsb-3.0-noarch:qt4-3.1-ia32:qt4-3.1-noarch
If you do get this output, you have a LSB compliant distro (Ubuntu surely is LSB-compliant, but you can check anyway). Then you just need to compile your applications according to LSB rules (export LSB_MODULES=Qt4, qmake && make).