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

    make sub-src

    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
    [root@linux qt4]#

    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
    total 108
    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
    [root@linux qt4.5.3]#

    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/
    [root@linux systray]#

    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:

    qmake -project

    but the result doesn't seem to have the libraries linked in statically to my executable "systray":

    [root@linux systray]# ldd systray => (0x00ea4000) => /usr/lib/ (0x00286000) => /usr/lib/ (0x001bd000) => /usr/lib/ (0x06701000) => /usr/lib/ (0x066e5000) => /usr/lib/ (0x002d3000) => /usr/lib/ (0x00c60000) => /usr/lib/ (0x001ab000) => /usr/lib/ (0x00cc6000) => /lib/ (0x00c4b000) => /lib/ (0x00c40000) => /lib/ (0x00b1b000) => /lib/ (0x00b22000) => /usr/lib/ (0x03926000) => /lib/ (0x00af1000) => /lib/ (0x03a22000) => /lib/ (0x0097f000) => /lib/ (0x066ba000) => /lib/ (0x0090d000) => /usr/lib/ (0x00ca3000) => /usr/lib/ (0x00ca8000)
    /lib/ (0x0095c000)
    [root@linux systray]#

    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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.