Nominate our 2022 Qt Champions!

[Moved] Qt4 application complete on linux! Now how to build it statically?

  • I have completed one of my Qt4 projects and am looking to deployment options. I do not want to have to install Qt4SDK on every system that this application goes on. From my research I have found building the application statically would be the way to go.

    I have read and got no where. I can see which dependencies that I require when I do the ldd command.

    This is my output: => (0x00bd6000) => /home/user/QtSDK/Desktop/Qt/473/gcc/lib/ (0x00d87000) => /home/user/QtSDK/Desktop/Qt/473/gcc/lib/ (0x00753000) => /lib/tls/i686/cmov/ (0x00110000) => /usr/lib/ (0x0024a000) => /lib/tls/i686/cmov/ (0x00c58000) => /lib/ (0x00af9000) => /lib/tls/i686/cmov/ (0x003f4000) => /usr/lib/ (0x00129000) => /lib/tls/i686/cmov/ (0x0012f000) => /lib/ (0x00138000) => /lib/ (0x00aba000) => /lib/ (0x00202000) => /usr/lib/ (0x00340000) => /usr/lib/ (0x0054e000) => /usr/lib/ (0x00217000) => /usr/lib/ (0x00220000) => /usr/lib/ (0x00239000) => /usr/lib/ (0x003b6000) => /usr/lib/ (0x0058d000) => /usr/lib/ (0x0059d000) => /lib/tls/i686/cmov/ (0x00243000)
    /lib/ (0x00d6a000) => /lib/ (0x00a63000) => /lib/ (0x003e6000) => /lib/ (0x006ba000) => /usr/lib/ (0x006e1000) => /usr/lib/ (0x003eb000) => /usr/lib/ (0x00b66000)

    Now I am not sure what to do to add them statically to my project...

    I am using Qt4 and the QtDesigner on Linux...

    • You do not need to install the Qt SDK on every target machine, just the Qt libraries. Most probably they are already installed.
    • You will have to build a static set of the Qt libraries (tons of threads on how to in these forums and the web), then link these libraries statically against your application.
    • Linking against a static version of the Qt libraries usually qualifies for a commercial license, unless the project is released under the terms of the LGPL or GPL as well.

  • The most comfortable way for Linux users is to provide a package for the major distributions, most notably a .deb or .rpm. Once you have set up the correct dependencies, the package managers should pull in the required libs. You might want to look at an existing package to cheat some details :-)

    As an alternative for the distributions that you do not provide a package for, you can setup a directory, including your executable, the libs necessary to run it, and maybe some additional data. In order to start the app, I would provide a short shell script then that sets up some environment variables (like LD_LIBRARY_PATH).

  • Thank you for the post. I have tried to create a .deb before it is was kind of over my head...

    So when I build my Qt4 App, it creates a folder (if in debug version) or likewise adds an executable to my current project directory. I can go in that project and open the executable and my application opens.

    Will this be the same when I bring it to another linux machine without the Qt4 SDK installed on it?

    The .deb would make that automated, yet I couldn't figure it out so that is out of the question right now.

  • No. On another machine you need to have the Qt 4 libs available, either by providing it yourself or by using a preinstalled version of the system.

    For a .deb or a .rpm, you usually will not pack the Qt libs into the installer but set a dependency, so that another package will be installed automatically ifs contents are missing.

Log in to reply