Qt shared with static runtime on win



  • Hi,
    I need to create a win app for the Desktop that can be installed also by not admin users.
    But the vc_redist can be installed only by admins.

    So I need to compile qt and my app with these flags:
    -shared -static-runtime

    If I try to compile qt sources with this configuration I get an error because it says that -static-runtime flag can be used only in combination with -static.
    I think that it should technically possible to compile qt sources producing dlls (shared) but using the static runtime (-static-runtime or /MT), isn't it?

    Can you help me on this, please?

    Thank you in advance

    Regards,

    Emanuele



  • Compiling Qt statically implies that you either have a commercial Qt license (if you want to keep your application source closed), otherwise you'll need to license your application as GPL and distribute its source code.

    Why not simply include the redist dlls in your installer which put them in the same directory as your application? That way you can use Qt as LPGL and keep your application' code closed.



  • Hi,
    thank you for your answer.
    I have to understand exactly which dlls are installed by the redist.
    Do you have a suggestion on how to check exactly all the dlls installed by redist and where?
    Also I am not sure if the redist installer does some other useful things like writing the registry, ...

    For what I understand, I think that recompiling qt dlls with runtime-static doesn't require a commercial license because my application will continue to use qt dlls as before (lgpl).
    Maybe I am wrong on this, so it could be good if someone could explain exactly on this aspect of qt.

    My intention is not to compile qt with the -static flag, but only with -static-runtime only.
    But the script for compiling qt doesn't allow -shared -static-runtime flags at the same time.
    And this shouldn't have a technical reason because producing dlls that don't need the redist should be possible without problems.

    Regards,

    Emanuele



  • It seems not to be possible to use -shared and -static-runtime together.

    It is actually quite simple. You probably have the windeployqt tool witihin the bin directory of your current Qt installation. This tool does exactly what you want. Simply do this:

    c:\path\to\qt\bin\windeployqt.exe --compiler-runtime c:\path\to\my\application.exe
    

    It will gather all required dlls by your application including the runtime ones.

    Alternatively:

    Usually the Visual Studio redist will install a couple of DLL's. Using dependency walker it is quite easy to figure out which DLLs are required by your application. It may even be easier for you, depending on your Visual Studio version you can have a look in the following folder (14.0 = Visual Studio 2015, change accordingly to your version):

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist
    

    You'll find a couple of folders which are of interest. If you're building a 32 bit application you'll need to go to the following folder:

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\x86\Microsoft.VC140.CRT
    

    Within that folder you find the DLLs as distributed by the redist package. Just copy these and put them near your executable. Furthermore you may need an additional DLL (ucrtbased.dll). This can be found in the Windows SDK directory using the same directory structure as for Visual Studio.



  • @bludger said in Qt shared with static runtime on win:

    It seems not to be possible to use -shared and -static-runtime together.

    It is actually quite simple. You probably have the windeployqt tool witihin the bin directory of your current Qt installation. This tool does exactly what you want. Simply do this:

    c:\path\to\qt\bin\windeployqt.exe --compiler-runtime c:\path\to\my\application.exe
    

    It will gather all required dlls by your application including the runtime ones.

    I already tried this, but it simply copy the vc_redist.x64.exe setup into destination folder, but then you need to be admin to install it, and in my case the app must be installed also if you are not admin

    Alternatively:

    Usually the Visual Studio redist will install a couple of DLL's. Using dependency walker it is quite easy to figure out which DLLs are required by your application.

    Dependency Walker get stuck analizing my simple application. And with this solution maybe I have to analyze also all qt dlls to be sure about their deps.

    It may even be easier for you, depending on your Visual Studio version you can have a look in the following folder (14.0 = Visual Studio 2015, change accordingly to your version):

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist
    

    You'll find a couple of folders which are of interest. If you're building a 32 bit application you'll need to go to the following folder:

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\x86\Microsoft.VC140.CRT
    

    Within that folder you find the DLLs as distributed by the redist package. Just copy these and put them near your executable. Furthermore you may need an additional DLL (ucrtbased.dll). This can be found in the Windows SDK directory using the same directory structure as for Visual Studio.

    This last solution could be interesting. I gonna try to copy the dlls contained in the following folder:
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Redist\MSVC\14.16.27012\x64\Microsoft.VC141.CRT
    into my app folder and see if my app complains for missing dlls.

    Thank you for now for your help, I hope it works


  • Lifetime Qt Champion

    @bludger said in Qt shared with static runtime on win:

    Compiling Qt statically implies that you either have a commercial Qt license (if you want to keep your application source closed), otherwise you'll need to license your application as GPL and distribute its source code.

    That's wrong. You are allowed to do that but it's pretty hard to comply with the LGPL requirements when using a static build. That's nothing specific to Qt though, any LGPL library will generate the same troubles.



  • @SGaist
    But to don't have any problem at all should be nice to have -shared -static-runtime flags available at the same time.


  • Moderators

    @3cxitalydev said in Qt shared with static runtime on win:

    I need to create a win app for the Desktop that can be installed also by not admin users.
    But the vc_redist can be installed only by admins.

    One option is to use the MinGW compiler. Then, you can distribute the MinGW DLLs directly with your app so the user doesn't need to install vc_redist.



  • @JKSH said

    One option is to use the MinGW compiler. Then, you can distribute the MinGW DLLs directly with your app so the user doesn't need to install vc_redist.

    This is why I have switched from Visual Studio to MinGW (also for example Qt's installation program has switched).


 

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