Static build Qt 5.9.2 using MinGw on Windows 10
I am having trouble making fully independent, statically-linked apps using MinGw 7.1 and Qt 5.9.2 on Windows 10 - the symptom is missing dlls at run-time.
For background, I have successfully built Qt 5.9.2 using MinGw 7.1, and have successfully used this build on a number of somewhat complex (i.e. they require multiple homegrown and 3rd-party libraries) Qt projects. I use multiple computers but only have MinGw, Qt and some of the 3rd party libraries on one of them. In order to use the Qt apps on all of my systems, I am trying to get a static build of the Qt apps. FWIW, I already have multiple non-Qt apps that I have statically linked and use in this fashion.
To accomplish statically-linked Qt apps, I have also built a statically-linked version of Qt5.9.2 (configure -static ...), which largely appears to work correctly. Unfortunately, when I try to run any Qt apps in a standalone fashion (a bit more about my testing strategy below), I get two run-time errors, each of the form
"The code execution cannot proceed because [dll] was not found. ...".
The missing dlls are libgcc_s_dw2-1.dll and libstdc++-6.dll, both of which are part of the standard MinGw libraries.
For test purposes, I used the standard Qt example program ..../Examples/Qt-5.9.2/widgets/mainwindows/application/
The way I test whether the statically-linked app likely to run on the other machines is to simply create a local environment with a restricted definition of the PATH environmental variable (This strategy has been useful and effective for many prior apps). The above-reference error happens when I don't include the standard MinGw libraries in my path. NOTE: paths for the Qt and other libraries don't need to be in PATH. If the MinGw path is included, the example app works fine - without it, the app fails.
Any suggestions for finding out who is requiring these dlls and how to get that required functionality statically linked?
Thanks in advance
AFAIK will you have always to use those dlls which are from the MinGW compiler.
When you have recompiled Qt for static linking this is only the compilation of Qt linking everything to full libs instead of the stubs required as for dlls.
Try to create a static hello world or a bit more application without involving Qt. My guess is that you will require those dlls regardless of not having any bit of Qt libs used. Therefore, the best place would be in the MinGW forum to find a solution where no MinGW dlls required.
As I mentioned in my original post, I have quite a number of other applications that DO NOT require those (or any other) MinGw libraries to be present at run-time.
Sorry, did not see that you mentioned that in your post.
I remember some discussions along those lines and I think there was no solution and for some reason these dlls are required, but I could be wrong.
Yes, I saw many such discussions. Some of them even reported success, but always for somewhat different circumstances than mine. Most importantly, I do not recall seeing any that identified why it "shouldn't" be possible to build apps fully statically-linked. Since I successfully do that for non-Qt apps, I'd like for someone to point out why it is impossible for Qt apps. My suspicion is that there is something in the Qt build process, which is a bit to complex for me to follow in its entirety, that leads to this outcome.
I'm afraid I'm not a Qt expert person, and I don't build Qt, use statics or MinGw or Windows. But I am just a curious reader!
When you "build Qt with MinGw", is the output one
.LIBfiles? Can you use a tool like
DUMPBINor dependency viewer so that you can start by finding where your MinGw
.DLLs are actually being referenced from?
Well, that's an interesting approach I hadn't considered. Up til now, I've never known about or used such tools. As for the Qt build output, it produces something like 100-200 individual lib files. Can you point me to any user info about LIB or DUMPBIN? A quick google search pointed me to Visual Studio tools, but I don't have Visual Studio.
Yeah, well, I actually expected you to know more about this than I! I was MSVC, never MinGw. thought some of these tools were available outside MSVC. Does your MinGw have its own linker or does it use
LINK? Are its
LIBfiles same as those from any other compiler or only its own format for its own linker? Really we're looking perhaps for a tool supplied with MinGw which can tell you what outside world references a
LIBfile is making?
MinGw uses the GNU compiler/linker g++. I don't know enough detail to know how that relates to MSVC.
Again, I'm hoping ultimately to learn where in the build process for Qt Apps something is done that assumes required libs are shared rather than static. A dependency viewer may inform that, but is likely to involve a fair bit of wasted effort by someone like me.