c++qtstaticopensslqtnetwork

Is there any way to building static Qt with static OpenSSL?


Original question was slightly different but part of a more major question.

I am trying to build Qt 5.2 as static with static OpenSSL on Windows.

My final goal is to ship a single binary without the need to provide libeay32.dll and ssleay32.dll with it. However, it seems to me that this is impossible. I built static Qt with static openssl libs but it seems like Qt is outright ignoring the libs provided and always searches for DLLs.

This answer also suggests that QtNetwork always searches for DLLs and ignores everything else but it also states that "two options are to compile OpenSSL into Qt..." but this does not seem to be the case.

Can someone provide a definitive answer?

This is my Qt configure (line breaks added for readability):

configure -static -qmake -opensource -nomake examples -opengl desktop
-platform win32-msvc2010 -openssl -I C:\git\openssl\build\include
-L C:\git\openssl\build\lib OPENSSL_LIBS="-llibeay32 -lssleay32 -lgdi32"

Solution

  • Is there any way to building static Qt with static OpenSSL?

    Sure, you need to use the following option when configuring Qt:

    -openssl-linked
    

    The reason is that QtNetwork uses the QLibrary class by default for dynamically opening the library to get the necessary symbols.

    This is the option to tell Qt not to do so, and respect the the normal linkage rules.

    That being said, it is not recommended to use static linkage for openssl if security updates need to be available for the end user without your involvement. Consider that for a moment what happens if you are gone, not working on this project anymore, etc.

    Also, this setup is not tested frequently, so you may actually encounter some issues that should be fixed upstream, but this is solution design for the use case in question.

    Disclaimer: since SO is about programming, I am ignoring the licensing consequences for static linking againt Qt, so I would just like to quickly remind that you that be aware of the proper usage not to get into legal troubles.