Cannot Install Static Libraries Correctly (Linux Platform)
I have created a QT program on Linux. I wanted to be able to link it statically so that it would not require the user to install a lot of libraries. I have followed the instructions I saw here:
but it hasn't worked.
I downloaded qt-x11-opensource-src-4.5.3.tar.gz to get the static versions of the libraries. I untarred it, and then ran configure and make. I gave the commands:
./configure -static -prefix /lib/qt
The instructions said that the last parameter in the configure command was the location where the libraries would be installed, so I created a qt directory under /lib. In fact, nothing was installed there. Everything went into the directory created by the untarring, from which I had run these commands. I tried to figure out where I should put the directories and files produced. In order to figure out where to put everything, I looked at the existing installation. First of all, most of the libraries of the existing installation were in /usr/lib. So I moved the new lib*.a files there. I also noticed that there was a directory /usr/lib/qt4 for the existing installation with the contents:
[root@linux qt4]# ls -l
drwxr-xr-x. 2 root root 4096 2011-07-08 18:38 bin
drwxr-xr-x. 98 root root 4096 2011-07-08 18:38 mkspecs
drwxr-xr-x. 2 root root 4096 2011-07-08 18:37 phrasebooks
drwxr-xr-x. 15 root root 4096 2011-07-08 18:37 plugins
-rw-r--r--. 1 root root 333331 2010-02-11 10:55 q3porting.xml
I tried to create something similar for the new stuff. I created /usr/lib/qt4.5.3 and moved all directories created by the new make there. The contents of the new directory are:
[root@linux qt4.5.3]# ls -l
drwxrwxr-x. 2 root root 4096 2011-07-20 18:04 bin
-rw-rw-r--. 1 root root 4933 2009-09-29 07:01 changes-4.5.3
drwxrwxr-x. 25 root root 4096 2011-07-20 17:50 demos
drwxrwxr-x. 5 root root 4096 2009-09-29 07:02 doc
drwxrwxr-x. 35 root root 4096 2011-07-20 17:50 examples
drwxrwxr-x. 24 root root 4096 2009-09-29 07:03 include
drwxrwxr-x. 3 root root 4096 2011-07-20 18:32 lib
-rw-rw-r--. 1 root root 36245 2009-09-29 07:01 LICENSE.GPL3
-rw-rw-r--. 1 root root 26436 2009-09-29 07:01 LICENSE.LGPL
drwxrwxr-x. 88 root root 4096 2011-07-20 17:49 mkspecs
drwxr-xr-x. 12 root root 4096 2011-07-20 17:52 plugins
drwxrwxr-x. 22 root root 4096 2011-07-20 17:50 tools
As you can see, the libraries are here too, as well as in /usr/lib. Finally, I changed the profiles (.bashrc files) for the root password and for my own to replace:
I then tried to build my project:
[root@linux systray]# qmake -project
[root@linux systray]# qmake
QMAKESPEC has not been set, so configuration cannot be deduced.
Error processing project file: /home/BShaw/workspace/InvScreens/InvScreens/Release/systray/systray.pro
I followed the instructions. What needs to be changed or added???
But, did you run make install after make, right?
Oops. I'm kind of new to Linux, but I should have known that. Let me give it a try. I'll report back when I have a result.
Okay, I can now compile and make with:
but the result doesn't seem to have the libraries linked in statically to my executable "systray":
[root@linux systray]# ldd systray
linux-gate.so.1 => (0x00ea4000)
libpng12.so.0 => /usr/lib/libpng12.so.0 (0x00286000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x001bd000)
libSM.so.6 => /usr/lib/libSM.so.6 (0x06701000)
libICE.so.6 => /usr/lib/libICE.so.6 (0x066e5000)
libXrender.so.1 => /usr/lib/libXrender.so.1 (0x002d3000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x00c60000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x001ab000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x00cc6000)
libz.so.1 => /lib/libz.so.1 (0x00c4b000)
librt.so.1 => /lib/librt.so.1 (0x00c40000)
libdl.so.2 => /lib/libdl.so.2 (0x00b1b000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00b22000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x03926000)
libm.so.6 => /lib/libm.so.6 (0x00af1000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x03a22000)
libc.so.6 => /lib/libc.so.6 (0x0097f000)
libuuid.so.1 => /lib/libuuid.so.1 (0x066ba000)
libexpat.so.1 => /lib/libexpat.so.1 (0x0090d000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00ca3000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00ca8000)
I even stopped after "qmake - project" and added to the .pro file:
CONFIG -= shared
CONFIG += static
and it didn't make any difference.
Well, it's been several days. So....what, this product just doesn't work?
Well, what makes you think that the Qt libraries have not been linked to your application statically (according to your ldd output they are)?
If you want to do single file deployment (a fully static application) you will have to provide static versions of all the dependencies and then configure, build and link the Qt libraries and your application properly (using no-* and qt-* configure switches, -static QMAKE_LFLAGS and static CONFIG).
However, this is usually not what you want to do just to simplify the installation procedure (this is what dynamic loaders and package managers are for). If you decide to go down this route be aware of headwind (increased binary sizes, name service issues with static libc linkages, exception issues with static mingw linkages and so on).
Libraries are usually not intended to be used static.
It's Qt, not QT.
A highly informative answer. Thank you! I've slowly learned some of what you just said over the past month that I've been trying for static linking, and I've communicated it to my management. I would like to go with a configure script instead of static linking. They acknowledge it, but for this alpha testing release it has to be done this way. Are you saying that it did in fact do the static linking, but linked dynamically where it had no choice, and that is what ldd is showing me?
The ldd output shows you basically two things
- your Qt libraries have been linked statically, as there are no runtime dependencies on it
- your application still has some runtime dependencies, some of them are Qt specific, some of them are C++ specific and are not directly related to Qt
Using the static option when configuring Qt just means to create a static version of the Qt library itself, not of its dependencies. You can instruct Qt to incorporate most of its dependencies using the qt-* switches (see ./configure --help) and to link the remaining ones (-static QMAKE_LFLAGS) statically.
That's theory. In praxis you might encounter various problems which will consume time and will be hard to track down.
[quote author="BrandonShw" date="1311617917"]... I've communicated it to my management.[/quote]
Linking Qt statically usually qualifies for a commercial Qt license.