Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Static linking fails for Qt libs.
Forum Updated to NodeBB v4.3 + New Features

Static linking fails for Qt libs.

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 5 Posters 4.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ademmlerA ademmler

    Hello there,

    I use a commercial Qt, with all static libs on board, trying to compile a cmdline tool statically. It seems like the qt components are still dynamically liked. Hints or remarks are welcome.

    This is from my *.pro file.

    QT       += core xml
    TARGET = cmdtool
    CONFIG += c++11
    CONFIG += static static-runtime
    CONFIG += COMPILE_64
    CONFIG += cmdline
    

    The result from a test with ldd:

    libQt5Core.so.5 => /home/user/Qt/5.15.16/gcc_64/lib/libQt5Core.so.5 (0x00007f4345600000)
       libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4345200000)
       libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4347528000)
       libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4347506000)
       libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4344e00000)
       libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4347501000)
       libGL.so.1 => /lib/x86_64-linux-gnu/libGL.so.1 (0x00007f4346f79000)
       libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f4346f5d000)
    
    ... and many more ...
    

    Environment:
    Qt 5.15.16 comecial with static libs
    Linux ubuntu222 6.2.0-37-generic #38~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 2 18:01:13 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

    kkoehneK Offline
    kkoehneK Offline
    kkoehne
    Moderators
    wrote on last edited by
    #2

    This is from my *.pro file.

    QT += core xml
    TARGET = cmdtool
    CONFIG += c++11
    CONFIG += static static-runtime

    Note that static-runtime is a Windows only setting. CONFIG += static will only mean that your libs will be built statically, it doesn't influence the Qt libs.

    libQt5Core.so.5 => /home/user/Qt/5.15.16/gcc_64/lib/libQt5Core.so.5 (0x00007f4345600000)

    This looks indeed like a dynamic build of Qt is used - and, from the path, a Qt as provided by the Qt online installer. If you want to link Qt libs statically, you need to rebuild it yourself, with '-static' argument: see e.g. https://doc.qt.io/qt-5/linux-deployment.html#static-linking.

    libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4345200000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4347528000)

    Even with a statically build Qt , you will still have these dependencies to system libs.

    Director R&D, The Qt Company

    ademmlerA 1 Reply Last reply
    2
    • B Offline
      B Offline
      BwvB
      wrote on last edited by
      #3

      Have you checked where on your system the static qt-libraries reside? Do they live in the same directory as the dynamic ones?
      Perhaps you can give the actual link command, so that you can see what qmake is doing. That might be revealing. (how to do that with qmake, I really don't anymore, sorry.)

      ademmlerA 1 Reply Last reply
      0
      • B BwvB

        Have you checked where on your system the static qt-libraries reside? Do they live in the same directory as the dynamic ones?
        Perhaps you can give the actual link command, so that you can see what qmake is doing. That might be revealing. (how to do that with qmake, I really don't anymore, sorry.)

        ademmlerA Offline
        ademmlerA Offline
        ademmler
        wrote on last edited by
        #4

        @BwvB

        I am actually compiling qt with static libs. After this I try again.
        also I can swap to cmake (As it seems to be recommended).
        I'll let you know about my success ...

        B 1 Reply Last reply
        0
        • kkoehneK kkoehne

          This is from my *.pro file.

          QT += core xml
          TARGET = cmdtool
          CONFIG += c++11
          CONFIG += static static-runtime

          Note that static-runtime is a Windows only setting. CONFIG += static will only mean that your libs will be built statically, it doesn't influence the Qt libs.

          libQt5Core.so.5 => /home/user/Qt/5.15.16/gcc_64/lib/libQt5Core.so.5 (0x00007f4345600000)

          This looks indeed like a dynamic build of Qt is used - and, from the path, a Qt as provided by the Qt online installer. If you want to link Qt libs statically, you need to rebuild it yourself, with '-static' argument: see e.g. https://doc.qt.io/qt-5/linux-deployment.html#static-linking.

          libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4345200000)
          libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4347528000)

          Even with a statically build Qt , you will still have these dependencies to system libs.

          ademmlerA Offline
          ademmlerA Offline
          ademmler
          wrote on last edited by
          #5

          @kkoehne thx I ll try this out.
          I thought commercial comes with static libs - but not with all (core etc ...) - as I understood now it just gives me permission to do the static linking.
          I am actually compiling qt with static libs ...

          1 Reply Last reply
          0
          • ademmlerA ademmler

            @BwvB

            I am actually compiling qt with static libs. After this I try again.
            also I can swap to cmake (As it seems to be recommended).
            I'll let you know about my success ...

            B Offline
            B Offline
            BwvB
            wrote on last edited by
            #6

            @ademmler Interested to see how you proceed. My experience is that changing to cmake is definitively a good plan. My experiences with static libs and qt vary, though. It always took some additional and unexpected work to get it working.

            ademmlerA 1 Reply Last reply
            0
            • B BwvB

              @ademmler Interested to see how you proceed. My experience is that changing to cmake is definitively a good plan. My experiences with static libs and qt vary, though. It always took some additional and unexpected work to get it working.

              ademmlerA Offline
              ademmlerA Offline
              ademmler
              wrote on last edited by
              #7

              @BwvB true ....

              Does somebody now if and where Qt saves a "compile" log?

              jsulmJ 1 Reply Last reply
              0
              • ademmlerA ademmler

                @BwvB true ....

                Does somebody now if and where Qt saves a "compile" log?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @ademmler Qt is a framework, it does not have any compile log. Compile log is simply the output of the compiler during the build.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                ademmlerA 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @ademmler Qt is a framework, it does not have any compile log. Compile log is simply the output of the compiler during the build.

                  ademmlerA Offline
                  ademmlerA Offline
                  ademmler
                  wrote on last edited by
                  #9

                  @jsulm thx for your response.

                  As Qt documentation says "Building Qt for Static Linking To use static linking, Qt must be built with the -static configuration option."

                  Hence I am compiling the Framework statically.
                  Now I am asking if there is a "log file" saved by default?
                  Might be an option in Qt configure ?

                  jsulmJ 1 Reply Last reply
                  0
                  • ademmlerA ademmler

                    @jsulm thx for your response.

                    As Qt documentation says "Building Qt for Static Linking To use static linking, Qt must be built with the -static configuration option."

                    Hence I am compiling the Framework statically.
                    Now I am asking if there is a "log file" saved by default?
                    Might be an option in Qt configure ?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @ademmler I don't understand what exactly you're asking. You see the build log (compiler/linker output) while you're building. If you want to have it in a file then simply forward the output to a file.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    ademmlerA 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @ademmler I don't understand what exactly you're asking. You see the build log (compiler/linker output) while you're building. If you want to have it in a file then simply forward the output to a file.

                      ademmlerA Offline
                      ademmlerA Offline
                      ademmler
                      wrote on last edited by
                      #11

                      @jsulm My host crashed while compile.
                      My simple question: Is there a log saved by default?

                      This might be the case - Qt is a beast and who knows everything what's going on in the background.

                      jsulmJ B 2 Replies Last reply
                      0
                      • ademmlerA ademmler

                        @jsulm My host crashed while compile.
                        My simple question: Is there a log saved by default?

                        This might be the case - Qt is a beast and who knows everything what's going on in the background.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @ademmler said in Static linking fails for Qt libs.:

                        My host crashed while compile

                        How exactly do you build on this host?

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        ademmlerA 1 Reply Last reply
                        0
                        • ademmlerA ademmler

                          @jsulm My host crashed while compile.
                          My simple question: Is there a log saved by default?

                          This might be the case - Qt is a beast and who knows everything what's going on in the background.

                          B Offline
                          B Offline
                          BwvB
                          wrote on last edited by
                          #13

                          @ademmler
                          Maybe you can be a bit more specific:

                          How did you configure exactly. How did you run the compilation. And what do you mean with a crashing host.
                          It broke down? You had to restart the machine?

                          Regards
                          Bertwim

                          1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @ademmler said in Static linking fails for Qt libs.:

                            My host crashed while compile

                            How exactly do you build on this host?

                            ademmlerA Offline
                            ademmlerA Offline
                            ademmler
                            wrote on last edited by ademmler
                            #14

                            @jsulm @BwvB

                            To be precise it was after compile!
                            I was reading the output from make - as my virtual machine collapsed.
                            Because it took 12h to compile I am asking if there is somewhere a log file by default.

                            However, now I got problem on top:
                            When I try to launch qtcreator it fails.

                            Possible reason:

                            • Qt5static is the default - which was compiled without plattform plugins
                            • Conflicts between different qt Versions
                              5.15.16 dynamic (from installer)
                              5.15.16 static (compiled by me)

                            When I use qtchooser it has no effect
                            When I set QT_SELECT no effect.

                            ./qmake -query
                            QT_SYSROOT:
                            QT_INSTALL_PREFIX:/home/user/Qt/5.15.16/gcc_64
                            QT_INSTALL_ARCHDATA:/home/user/Qt/5.15.16/gcc_64
                            QT_INSTALL_DATA:/home/user/Qt/5.15.16/gcc_64
                            QT_INSTALL_DOCS:/home/user/Qt/Docs/Qt-5.15.16
                            QT_INSTALL_HEADERS:/home/user/Qt/5.15.16/gcc_64/include
                            QT_INSTALL_LIBS:/home/user/Qt/5.15.16/gcc_64/lib
                            QT_INSTALL_LIBEXECS:/home/user/Qt/5.15.16/gcc_64/libexec
                            QT_INSTALL_BINS:/home/user/Qt/5.15.16/gcc_64/bin
                            QT_INSTALL_TESTS:/home/user/Qt/5.15.16/gcc_64/tests
                            QT_INSTALL_PLUGINS:/home/user/Qt/5.15.16/gcc_64/plugins
                            QT_INSTALL_IMPORTS:/home/user/Qt/5.15.16/gcc_64/imports
                            QT_INSTALL_QML:/home/user/Qt/5.15.16/gcc_64/qml
                            QT_INSTALL_TRANSLATIONS:/home/user/Qt/5.15.16/gcc_64/translations
                            QT_INSTALL_CONFIGURATION:/home/user/Qt/5.15.16/gcc_64
                            QT_INSTALL_EXAMPLES:/home/user/Qt/Examples/Qt-5.15.16
                            QT_INSTALL_DEMOS:/home/user/Qt/Examples/Qt-5.15.16
                            QT_HOST_PREFIX:/home/user/Qt/5.15.16/gcc_64
                            QT_HOST_DATA:/home/user/Qt/5.15.16/gcc_64
                            QT_HOST_BINS:/home/user/Qt/5.15.16/gcc_64/bin
                            QT_HOST_LIBS:/home/user/Qt/5.15.16/gcc_64/lib
                            QMAKE_SPEC:linux-g++
                            QMAKE_XSPEC:linux-g++
                            QMAKE_VERSION:3.1
                            QT_VERSION:5.15.16
                            
                            jsulmJ 1 Reply Last reply
                            0
                            • ademmlerA ademmler

                              @jsulm @BwvB

                              To be precise it was after compile!
                              I was reading the output from make - as my virtual machine collapsed.
                              Because it took 12h to compile I am asking if there is somewhere a log file by default.

                              However, now I got problem on top:
                              When I try to launch qtcreator it fails.

                              Possible reason:

                              • Qt5static is the default - which was compiled without plattform plugins
                              • Conflicts between different qt Versions
                                5.15.16 dynamic (from installer)
                                5.15.16 static (compiled by me)

                              When I use qtchooser it has no effect
                              When I set QT_SELECT no effect.

                              ./qmake -query
                              QT_SYSROOT:
                              QT_INSTALL_PREFIX:/home/user/Qt/5.15.16/gcc_64
                              QT_INSTALL_ARCHDATA:/home/user/Qt/5.15.16/gcc_64
                              QT_INSTALL_DATA:/home/user/Qt/5.15.16/gcc_64
                              QT_INSTALL_DOCS:/home/user/Qt/Docs/Qt-5.15.16
                              QT_INSTALL_HEADERS:/home/user/Qt/5.15.16/gcc_64/include
                              QT_INSTALL_LIBS:/home/user/Qt/5.15.16/gcc_64/lib
                              QT_INSTALL_LIBEXECS:/home/user/Qt/5.15.16/gcc_64/libexec
                              QT_INSTALL_BINS:/home/user/Qt/5.15.16/gcc_64/bin
                              QT_INSTALL_TESTS:/home/user/Qt/5.15.16/gcc_64/tests
                              QT_INSTALL_PLUGINS:/home/user/Qt/5.15.16/gcc_64/plugins
                              QT_INSTALL_IMPORTS:/home/user/Qt/5.15.16/gcc_64/imports
                              QT_INSTALL_QML:/home/user/Qt/5.15.16/gcc_64/qml
                              QT_INSTALL_TRANSLATIONS:/home/user/Qt/5.15.16/gcc_64/translations
                              QT_INSTALL_CONFIGURATION:/home/user/Qt/5.15.16/gcc_64
                              QT_INSTALL_EXAMPLES:/home/user/Qt/Examples/Qt-5.15.16
                              QT_INSTALL_DEMOS:/home/user/Qt/Examples/Qt-5.15.16
                              QT_HOST_PREFIX:/home/user/Qt/5.15.16/gcc_64
                              QT_HOST_DATA:/home/user/Qt/5.15.16/gcc_64
                              QT_HOST_BINS:/home/user/Qt/5.15.16/gcc_64/bin
                              QT_HOST_LIBS:/home/user/Qt/5.15.16/gcc_64/lib
                              QMAKE_SPEC:linux-g++
                              QMAKE_XSPEC:linux-g++
                              QMAKE_VERSION:3.1
                              QT_VERSION:5.15.16
                              
                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #15

                              @ademmler I as I wrote before you can forward compiler output to a file. But I don't know why you actually need it? Simply start the build again, it will continue where it was interrupted.

                              "When I try to launch qtcreator it fails" - start it ffom a terminal and see whether there are any errors.

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              ademmlerA 1 Reply Last reply
                              0
                              • jsulmJ jsulm

                                @ademmler I as I wrote before you can forward compiler output to a file. But I don't know why you actually need it? Simply start the build again, it will continue where it was interrupted.

                                "When I try to launch qtcreator it fails" - start it ffom a terminal and see whether there are any errors.

                                ademmlerA Offline
                                ademmlerA Offline
                                ademmler
                                wrote on last edited by
                                #16

                                @jsulm I wanted first to resolve missing stuff before I redo it.

                                jsulmJ 1 Reply Last reply
                                0
                                • ademmlerA ademmler

                                  @jsulm I wanted first to resolve missing stuff before I redo it.

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #17

                                  @ademmler said in Static linking fails for Qt libs.:

                                  I wanted first to resolve missing stuff before I redo it

                                  Reado what? I did not suggest to redo anything, I seggested to simply continue the build after crash. And what do you mean by "missing stuff"?

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0
                                  • B Offline
                                    B Offline
                                    BwvB
                                    wrote on last edited by
                                    #18

                                    I still have no idea what precisely you are doing. Apparently, ,you are working on a virtual machine.
                                    But you give no specifics about what you are really doing, other than in general terms.
                                    But do you work from a terminal? (if not, I strongly suggest doing so). In my personal experience this is the best way to have control over the whole procedure.

                                    When you compile/install from a terminal, the procedure is in principle straight forward; Forget about QtCreator. first make sure the Qt libs are installed properly. Once that is ok, you can proceed with QtCreator (although personally I am no fan).
                                    In the source tree, you have to run first the .configure script. It is all in the README.
                                    It will tell you which features will be enabled, disabled, or if there are any essential packages missing.
                                    You might have to run the configuration several times in order to satisfy all requirements.

                                    Next, once you have ensured that all essential packages are available on you virtual machine, you can go to the next phase:
                                    compilation. Is your cmake-toolchain ok?

                                    Assuming that the compilation succeeds, the next stage is to install. Qt will be installed in the directory you specify when you run the configure script, e.g. ./configure -prefix /usr/local/qt-6.6.1
                                    or ./configure -static -prefix /usr/local/qt-6.6.1-static
                                    This directory is important. I always make sure that the static version of Qt is install in a separate directory, e.g. /usr/local/qt-6.6.1-static. Moreover, once done, I ensure the environment variable QTDIR is set to this very directory. This way, you prevent version conflicts.

                                    You see, there is so much additional info needed to address your issue systematically.

                                    Good luck
                                    Bertwim

                                    ademmlerA 1 Reply Last reply
                                    0
                                    • B BwvB

                                      I still have no idea what precisely you are doing. Apparently, ,you are working on a virtual machine.
                                      But you give no specifics about what you are really doing, other than in general terms.
                                      But do you work from a terminal? (if not, I strongly suggest doing so). In my personal experience this is the best way to have control over the whole procedure.

                                      When you compile/install from a terminal, the procedure is in principle straight forward; Forget about QtCreator. first make sure the Qt libs are installed properly. Once that is ok, you can proceed with QtCreator (although personally I am no fan).
                                      In the source tree, you have to run first the .configure script. It is all in the README.
                                      It will tell you which features will be enabled, disabled, or if there are any essential packages missing.
                                      You might have to run the configuration several times in order to satisfy all requirements.

                                      Next, once you have ensured that all essential packages are available on you virtual machine, you can go to the next phase:
                                      compilation. Is your cmake-toolchain ok?

                                      Assuming that the compilation succeeds, the next stage is to install. Qt will be installed in the directory you specify when you run the configure script, e.g. ./configure -prefix /usr/local/qt-6.6.1
                                      or ./configure -static -prefix /usr/local/qt-6.6.1-static
                                      This directory is important. I always make sure that the static version of Qt is install in a separate directory, e.g. /usr/local/qt-6.6.1-static. Moreover, once done, I ensure the environment variable QTDIR is set to this very directory. This way, you prevent version conflicts.

                                      You see, there is so much additional info needed to address your issue systematically.

                                      Good luck
                                      Bertwim

                                      ademmlerA Offline
                                      ademmlerA Offline
                                      ademmler
                                      wrote on last edited by
                                      #19

                                      @BwvB Dear Bertwim,

                                      thx for your response. My mistake - i have mixed to topics here.

                                      1. Ofcourse I compile from terminal.
                                      2. After compile and "make install" I ended up with 2 Qt Version:
                                      • commercial license dynamic
                                      • self compiled static

                                      now I want to use Qtcreator for opening my project and work on this.
                                      But after the compile and install everything is screwed up and qtcreator won't start any longer - while maintenance tool still does ...

                                      My question: I need to select the right qt installation to be used with qtcreator ... how do I do this if the QT_SELECT has no effect?

                                      B 1 Reply Last reply
                                      0
                                      • ademmlerA ademmler

                                        @BwvB Dear Bertwim,

                                        thx for your response. My mistake - i have mixed to topics here.

                                        1. Ofcourse I compile from terminal.
                                        2. After compile and "make install" I ended up with 2 Qt Version:
                                        • commercial license dynamic
                                        • self compiled static

                                        now I want to use Qtcreator for opening my project and work on this.
                                        But after the compile and install everything is screwed up and qtcreator won't start any longer - while maintenance tool still does ...

                                        My question: I need to select the right qt installation to be used with qtcreator ... how do I do this if the QT_SELECT has no effect?

                                        B Offline
                                        B Offline
                                        BwvB
                                        wrote on last edited by BwvB
                                        #20

                                        @ademmler Ah, I see what you are after. I think if you know the qt-installation that is needed for QtCreator (the one that is given to you originally) you can set those in a separate script (e.g. a bash script). So ensure QTDIR and perhaps LD_LIBRARY_CONFIG in this script are referring to the original QtConfig; then start QtCreator from this script. You can start this selfmade QtCreator script from a desktop icon, if you want.
                                        In other words, ensure that in you script the environment is set ok for your copy of QtCreator. Then run this script.

                                        Success,
                                        Bertwim

                                        1 Reply Last reply
                                        0
                                        • S Offline
                                          S Offline
                                          SimonSchroeder
                                          wrote on last edited by
                                          #21

                                          I'm a little late to the party 😉. I have a comment about the original problem that there are some libraries which are dynamically linked. This could be solved for the Qt libs through recompilation (like you are trying), but it doesn't solve it for the other libraries. In any case it is a good idea to create an AppImage that has all the libraries included. In this case you can even include the Qt dynamic libraries into the AppImage. We are using a combination of linuxdeploy and linuxdeployqt to create the AppImage. In the end you have a single file that just looks like an executable to the end user (it is actually an executable which will mount the AppImage and run a specific command after that).

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved