Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Static compile application with OpenSSL fails if both static and dinamic OpenSSL libraries are installed
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
6 Posts 2 Posters 1.7k Views 1 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.
  • R Offline
    R Offline
    rokk
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rokk
        wrote on last edited by
        #3

        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..

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rokk
            wrote on last edited by
            #5

            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..

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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