Unable to link Qt application statically



  • Hi,

    I'm facing some problems with static linking of qt , I wrongly posted the query under
    " Mobile and Embedded " and i think this is the right place to get a perfect solution. so please take a look at the following link and give your valuable comments on it

    https://forum.qt.io/topic/66714/unable-to-link-qt-application-statically

    Thank you for your time and consideration..

    zappy


  • Lifetime Qt Champion

    Hi,

    You already had several good replies, no need to open such a thread.

    If you feel that you posted on the wrong sub-forum, just ask a moderator to move it.

    In your case, I think you choose the right place since you are struggling with an embedded target.



  • @SGaist

    Thank you.

    [WARNING: Using static linking will disable the use of dynamically
    loaded plugins. Make sure to import all needed static plugins,
    or compile needed modules into the library
    

    Could you please explain what this really means, Should I need to do anything more other than just make and make install. I'm really stuck with this..

    Thanks again


  • Lifetime Qt Champion

    This means that if you want to use e.g. the SQLite plugin you either make it built-in (choice done at configuration time) or you follow this documentation to use it in your application.



  • @SGaist
    Thank you for your valuable time.

    Tried that but getting same error

    Given the log after running configuration

    + cd qtbase
    + /root/Desktop/qt5-static/qt5/qtbase/configure -top-level -static -confirm-license -opensource -opengl es2 -eglfs -device linux-imx6-g++ -device-option CROSS_COMPILE=/home/acs/Desktop/gcc-linaro-5.2-2015.11-1-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- -sysroot /home/acs/Downloads/L3.14.52_1.1.0-ga_images_MX6QDLSOLO/fsl-image-qt5-fb-imx6qdlsolo -release --prefix=/my-qt
    
    This is the Qt Open Source Edition.
    
    You are licensed to use this software under the terms of
    the Lesser GNU General Public License (LGPL) versions 2.1.
    You are also licensed to use this software under the terms of
    the GNU Lesser General Public License (LGPL) versions 3.
    
    You have already accepted the terms of the Open Source license.
    
    Running configuration tests (phase 1)...
    Done running configuration tests.
    <srcbase> = /root/Desktop/qt5-static/qt5/qtbase 
    <outbase> = /root/Desktop/qt5-static/qt5/qtbase 
    Creating qmake...
    ..Done.
    Running configuration tests (phase 2)...
    Note: PKG_CONFIG_LIBDIR automatically set to /home/acs/Downloads/L3.14.52_1.1.0-ga_images_MX6QDLSOLO/fsl-image-qt5-fb-imx6qdlsolo/usr/lib/pkgconfig:/home/acs/Downloads/L3.14.52_1.1.0-ga_images_MX6QDLSOLO/fsl-image-qt5-fb-imx6qdlsolo/usr/share/pkgconfig:/home/acs/Downloads/L3.14.52_1.1.0-ga_images_MX6QDLSOLO/fsl-image-qt5-fb-imx6qdlsolo/usr/lib/arm-linux-gnueabihf/pkgconfig
    Note: PKG_CONFIG_SYSROOT_DIR automatically set to /home/acs/Downloads/L3.14.52_1.1.0-ga_images_MX6QDLSOLO/fsl-image-qt5-fb-imx6qdlsolo
    WARNING: Unable to find file .device.vars
    WARNING: Unable to find file .device.vars
    
    WARNING: Using static linking will disable the WebKit module.
    
    Done running configuration tests.
    
       Configure summary
    
    Building on:   linux-g++ (x86_64, CPU features: mmx sse sse2)
    Building for:  devices/linux-imx6-g++ (arm, CPU features: neon)
    Platform notes:
    
                - Also available for Linux: linux-clang linux-kcc linux-icc linux-cxx
            
    Build options:
      Configuration .......... accessibility alsa audio-backend c++11 c++14 c++1z clock-gettime clock-monotonic compile_examples concurrent cross_compile dbus dbus-linked egl eglfs eglfs_viv evdev eventfd fontconfig full-config getaddrinfo getifaddrs gif glib gstreamer-1.0 harfbuzz iconv inotify ipv6ifname jpeg large-config largefile libproxy libudev linuxfb medium-config minimal-config mremap neon nis opengl opengles2 openssl pcre png posix_fallocate precompile_header pulseaudio qpa qpa reduce_exports release rpath small-config static system-freetype system-jpeg system-png system-zlib threadsafe-cloexec 
      Build parts ............ libs examples
      Mode ................... release
      Using sanitizer(s)...... none
      Using C++ standard ..... c++1z
      Using gold linker....... no
      Using new DTAGS ........ no
      Using PCH .............. yes
      Using LTCG ............. no
      Target compiler supports:
        Neon ................. yes
    
    Qt modules and options:
      Qt D-Bus ............... yes (linked to dbus-1)
      Qt Concurrent .......... yes
      Qt GUI ................. yes
      Qt Widgets ............. yes
      Large File ............. yes
      QML debugging .......... yes
      Use system proxies ..... no
    
    Support enabled for:
      Accessibility .......... yes
      ALSA ................... yes
      CUPS ................... no
      Evdev .................. yes
      FontConfig ............. yes
      FreeType ............... yes (system library)
      Glib ................... yes
      GStreamer .............. yes (1.0)
      GTK theme .............. no
      HarfBuzz ............... yes (bundled copy)
      Iconv .................. yes
      ICU .................... no
      Image formats: 
        GIF .................. yes (in QtGui, using bundled copy)
        JPEG ................. yes (in QtGui, using system library)
        PNG .................. yes (in QtGui, using system library)
      libinput................ no
      Logging backends: 
        journald ............... no
        syslog   ............... no
      mtdev .................. no
      Networking: 
        getaddrinfo .......... yes
        getifaddrs ........... yes
        IPv6 ifname .......... yes
        libproxy.............. yes
        OpenSSL .............. yes (loading libraries at run-time)
      NIS .................... yes
      OpenGL / OpenVG: 
        EGL .................. yes
        OpenGL ............... yes (OpenGL ES 2.0+)
        OpenVG ............... no
      PCRE ................... yes (bundled copy)
      pkg-config ............. yes 
      PulseAudio ............. yes
      QPA backends: 
        DirectFB ............. no
        EGLFS ................ yes
          EGLFS i.MX6 ........ yes
          EGLFS i.MX6 Wayland. no
          EGLFS EGLDevice .... no
          EGLFS GBM .......... no
          EGLFS Mali ......... no
          EGLFS Raspberry Pi . no
          EGLFS X11 .......... no
        LinuxFB .............. yes
        Mir client............ no
        XCB .................. no
      Session management ..... yes
      SQL drivers: 
        DB2 .................. no
        InterBase ............ no
        MySQL ................ no
        OCI .................. no
        ODBC ................. no
        PostgreSQL ........... no
        SQLite 2 ............. no
        SQLite ............... yes (plugin, using bundled copy)
        TDS .................. no
      tslib .................. no
      udev ................... yes
      xkbcommon-x11........... no
      xkbcommon-evdev......... no
      zlib ................... yes (system library)
    
    
    WARNING: Using static linking will disable the use of dynamically
    loaded plugins. Make sure to import all needed static plugins,
    or compile needed modules into the library.
    
    NOTE: Qt is using double for qreal on this system. This is binary incompatible against Qt 5.1.
    Configure with '-qreal float' to create a build that is binary compatible with 5.1.
    Info: creating super cache file /root/Desktop/qt5-static/qt5/.qmake.super
    
    Qt is now configured for building. Just run 'make'.
    Once everything is built, you must run 'make install'.
    Qt will be installed into /my-qt
    
    Prior to reconfiguration, make sure you remove any leftovers from
    the previous build.
    
    

    And all the static library plugins are available in the corresponding directories in prefix path inside rootfs. But ld complains that it cannon found it.

    Tried Following that document about QPLUGIN, added following lines to pro file

    QTPLUGIN     += qdds \
                     qeglfs\
                    qicns \
                    qico \
                    qtga \
                    qtiff \
                    qwbmp \
                    qwebp \
                    qeglfs-viv-integration \
                    qconnmanbearer \
                    qmldbg_debugger \
                    qmldbg_inspector \
                    qmldbg_local \
                    qmldbg_native \
                    qmldbg_profiler \
                    qmldbg_server \
                    qmldbg_tcp \
                    qgenericbearer \
                    qnmbearer
    
    

    and in my main.cpp added the below code:

    #include <QtPlugin>
    Q_IMPORT_PLUGIN(qeglfs)
    Q_IMPORT_PLUGIN(qdds)
    Q_IMPORT_PLUGIN(qicns)
    Q_IMPORT_PLUGIN(qico)
    Q_IMPORT_PLUGIN(qtga)
    Q_IMPORT_PLUGIN(qtiff)
    Q_IMPORT_PLUGIN(qwbmp)
    Q_IMPORT_PLUGIN(qwebp)
    //Q_IMPORT_PLUGIN(qeglfs-viv-integration)
    Q_IMPORT_PLUGIN(qconnmanbearer)
    Q_IMPORT_PLUGIN(qmldbg_debugger)
    Q_IMPORT_PLUGIN(qmldbg_inspector)
    Q_IMPORT_PLUGIN(qmldbg_local)
    Q_IMPORT_PLUGIN(qmldbg_native)
    Q_IMPORT_PLUGIN(qmldbg_profiler)
    Q_IMPORT_PLUGIN(qmldbg_server)
    Q_IMPORT_PLUGIN(qmldbg_tcp)
    Q_IMPORT_PLUGIN(qgenericbearer)
    Q_IMPORT_PLUGIN(qnmbearer)
    
    

    Then qmake gives Waring like follow

    Project WARNING: Redundant entries in QTPLUGIN: qeglfs qdds qicns qico qtga qtiff qwbmp qwebp qeglfs-viv-integration qconnmanbearer qmldbg_tcp qgenericbearer qnmbearer
    Project WARNING: Plugin class name could not be determined for qmldbg_debugger plugin.
    Project WARNING: Plugin class name could not be determined for qmldbg_local plugin.
    Project WARNING: Plugin class name could not be determined for qmldbg_native plugin.
    Project WARNING: Plugin class name could not be determined for qmldbg_profiler plugin.
    Project WARNING: Plugin class name could not be determined for qmldbg_server plugin.
    

    And the make give same error as i have posted in the question.

    I konw i'm doing something really wrong,but i am unable to find where.
    Thanks again.


  • Lifetime Qt Champion

    Did you do as suggested and update your Qt version ?



  • @SGaist
    Yes I tried several times what i understand.

    Updated Qt to 5.6.1 and the result is same.
    Qt 4.8.7 work fine without any problem(It linked only Qt libraries statically).
    I really don't know what i am doing wrong

    Note: I don't want any extra plugins or custom made plugins to be added, What i only need is to adds the plugins to QTPLUGIN that are typically needed by the Qt modules.If my understanding is correct, it will be added by qmake automatically..


  • Lifetime Qt Champion

    I just realized something, why are you linking your application against the qml tooling plugins ?



  • Okay... finally i solved it. Nothing to do with .pro file or PLUGIN macro. It was a basic PATH issue. qmake was searching for 'plugin' directory in /PREFIX path not in /SYSROOT/PREFIX path. I just copied all plugin directory from /SYSROOT/PREFIX to /PREFIX directory. I know this may not be the right way, but it temporarily solved my issue. If someone could suggest the correct solution please let me know.



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