Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Correct way to use static openssl with self-builded Qt on Ubuntu



  • Hi,

    I'm not able to configure Qt to use OPENSSL compiled via vcpkg as a static library.

    export OPENSSL_LIBS="$OPENSSL_PATH/lib_release/libcrypto.a $OPENSSL_PATH/lib_release/libssl.a -L$OPENSSL_PATH/lib_release -ldl -lpthread"
    export OPENSSL_PREFIX=$OPENSSL_PATH
    export OPENSSL_INCDIR=$OPENSSL_PATH/include 
    export OPENSSL_LIBDIR=$OPENSSL_PATH/lib_release
    
    ./configure -openssl-linked ...
    

    But result libQt5Network.so has a dynamic reference to /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1

        linux-vdso.so.1 (0x00007ffe2ef31000)
        libQt5Core.so.5 => /root/dev/SharedLibraries/qt/lib/libQt5Core.so.5 (0x00007f3b06ec1000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3b06ca2000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f3b06a85000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f3b06881000)
        libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f3b065f4000)
        libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f3b06129000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f3b05da0000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3b059af000)
        libglib-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f3b05698000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f3b052fa000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f3b050e2000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f3b07afb000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f3b04e70000)
    

    I tried several configuration switches and methods on ./configure but still with the same result.

    This is my complete configure script:

    /root/dev/ExternalLibraries/librariesLinux/qt-everywhere-src-5.15.1/qtbase/configure -v -prefix /root/dev/ExternalLibraries/../SharedLibraries/qt -dbus -xcb-xlib -bundled-xcb-xinput -skip qt3d -skip activeqt -skip qtandroidextras -skip qtconnectivity -skip datavis3d -skip declarative -skip qtdoc -skip gamepad -skip qtgraphicaleffects -skip qtcharts -skip qtlocation -skip qtlottie -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquick3d -skip qtquickcontrols -skip qtquickcontrols2 -skip qtquicktimeline -skip qtremoteobjects -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qtvirtualkeyboard -skip qtwayland -skip qtwebengine -skip qtwebglplugin -skip qtwebchannel -skip qtwebsockets -skip qtwebview -skip qtxmlpatterns -no-opengl -no-openvg -nomake examples -nomake tests -confirm-license -opensource -D JAVASCRIPTCORE_JIT=NO -D ENABLE_JIT=0 -openssl-linked -skip qtscript

    Thanks for any help



  • I just found a reason. It's necessary to swap the order of libssl and libcrypto. This caused undefined references errors. But I'm not sure why ./configure doesn't report that.

    This is incorrect test:

    g++ -Wl,-O1 -o openssl main.o ~/dev/SharedLibraries/openssl/lib_release/libcrypto.a ~/dev/SharedLibraries/openssl/lib_release/libssl.a -ldl -lpthread

    This is a correct test

    g++ -Wl,-O1 -o openssl main.o ~/dev/SharedLibraries/openssl/lib_release/libssl.a ~/dev/SharedLibraries/openssl/lib_release/libcrypto.a -ldl -lpthread

    After this change, config.qtbase_network.libraries.openssl test is correclty passed:

    test config.qtbase_network.libraries.openssl succeeded

    OpenSSL seems to be configured correctly (but it was reported correct also before this change)

    Qt Network:
      getifaddrs() ........................... yes
      IPv6 ifname ............................ yes
      libproxy ............................... no
      Linux AF_NETLINK ....................... yes
      OpenSSL ................................ yes
        Qt directly linked to OpenSSL ........ yes
      OpenSSL 1.1 ............................ yes
      DTLS ................................... yes
      OCSP-stapling .......................... yes
      SCTP ................................... no
      Use system proxies ..................... yes
      GSSAPI ................................. no
    


  • I just found a reason. It's necessary to swap the order of libssl and libcrypto. This caused undefined references errors. But I'm not sure why ./configure doesn't report that.

    This is incorrect test:

    g++ -Wl,-O1 -o openssl main.o ~/dev/SharedLibraries/openssl/lib_release/libcrypto.a ~/dev/SharedLibraries/openssl/lib_release/libssl.a -ldl -lpthread

    This is a correct test

    g++ -Wl,-O1 -o openssl main.o ~/dev/SharedLibraries/openssl/lib_release/libssl.a ~/dev/SharedLibraries/openssl/lib_release/libcrypto.a -ldl -lpthread

    After this change, config.qtbase_network.libraries.openssl test is correclty passed:

    test config.qtbase_network.libraries.openssl succeeded

    OpenSSL seems to be configured correctly (but it was reported correct also before this change)

    Qt Network:
      getifaddrs() ........................... yes
      IPv6 ifname ............................ yes
      libproxy ............................... no
      Linux AF_NETLINK ....................... yes
      OpenSSL ................................ yes
        Qt directly linked to OpenSSL ........ yes
      OpenSSL 1.1 ............................ yes
      DTLS ................................... yes
      OCSP-stapling .......................... yes
      SCTP ................................... no
      Use system proxies ..................... yes
      GSSAPI ................................. no
    

Log in to reply