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

Static compile application with OpenSSL fails if both static and dinamic OpenSSL libraries are installed



  • Hi,
    I installed openSSL 1.1.1j on a custom using

    ./config --prefix=/opt/openssl --openssldir=/opt/openssl/ssl
    

    In this way on the prefix path I have libssl.a and libcrypto.a but also their shared version libssl.so and libcrypto.so as expected since I didn't specify that I did't want the shared librearies.

    Then I built Qt statically using this:

    ./init-repository --module-subset=qtbase,qtwebsockets,qtdeclarative
    
    OPENSSL_LIBS='-L/opt/openssl/lib -lssl -lcrypto' ./configure -static -prefix "/home/rocco/static_libraries/qt-5.15.2" -qt-harfbuzz -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -make libs -nomake tools -nomake examples -nomake tests -opensource -confirm-license -openssl-linked -I /opt/openssl/include -L /opt/openssl/lib
    

    Everything is fine, but when I try to build my application statically, no matter how I link openssl statically in my .pro file, the application is always linked to the shared library. I tried all the following (step by step) in .pro but none of them is working:

    LIBS += -L/opt/openssl/lib -lssl.a -lcrypto.a
    
    LIBS += -L/opt/openssl/lib -Wl,-Bstatic -lssl.a -lcrypto.a
    

    The only solution is to manually delete the shared libraries, in that case even without specifying the linking in the .pro, everything works. I would expect some sort of qmake variable to let me choose which version to link, but didn't find anything. Is there a way to choose between static and dynamic linking if I have both on my system ?


  • Lifetime Qt Champion

    Hi,

    From memory, if you want to link to the static version, when you have both in the same folder, you have to give the full path with the -l option.



  • I tried also in that way, but forgot to mention in the post. No Luck
    There must be some kind on mechanism in qmake to always prefer the shared library if present.. but this only happens with openssl, with other libraries it's fine just defining -Wl,-Bstatic . Maybe it's because static linking of openssl is not recommended for security and license issues and you have to be super-explicit in doing that ? (I'm just guessing..)
    At this point there must be a flag or something like that to instruct qmake to take the static version, but I didn't find any..


  • Lifetime Qt Champion

    It has nothing to do with qmake, the linker chooses.

    Can you show how you did configure your .pro file for use of static OpenSSL ?



  • I recap here for convenience.. I tried this 3 methods, none of them works but there are no errors.. shared version is always preferred.

    1)
    LIBS += -L/opt/openssl/lib -lssl.a -lcrypto.a
    
    2)
    LIBS += -L/opt/openssl/lib -Wl,-Bstatic -lssl.a -lcrypto.a
    
    3)
    LIBS += /opt/openssl/lssl.a /opt/openssl/lcrypto.a
    

    Just want to add that I don't directly use openSSL, but I use QtNetwork that uses it.. so now to make it working I just removed the shared libraries of openSSL and don't even mention openssl in the .pro file..


  • Lifetime Qt Champion

    Ok, I misunderstood your issue. There's no need to link OpenSSL to your application since you do not use it. It's a dependency of QtNetwork but it won't bleed up to your application.

    As for the linking part, I was thinking about version 3 with -l in front of each library path.


Log in to reply