This question already has an answer here:
- Qt static linking and deployment 6 answers
I know it might be a question similar to many others, but after searching for many times and failing to get a definitive and effective solution I'm having to ask this question.
I'm using Qt 5.2.0 for Windows 32-bit (VS 2010, 570 MB), and I have already made my programming, and it's all done. But now I want to distribute it as .exe file to my colleagues, but to do so without complication and to avoid having to distribute dll files I need to build the program using static linking.
Could you please describe how I can make Qt 5.2.0 for Windows 32-bit (VS 2010, 570 MB) build the whole program using static linking?
Thanks.
You can use the
CONFIG
variable for this with qmake:or
However, you will need to make sure that you have all the libraries that you wish to bundle up, available as static.
This includes the Qt framework itself as well if you comply with the license to do so. The official installation only sets up dynamic libraries (.dll files), so you would need to build Qt on your own to accomplish this.
You could use the following commands to build
Qt
statically for your own purpose:Note that in general when building third-party Qt softwares like yours, you better invoke
qmake
with the following parameter to pass your environment properly:Please also noted that as Frank and ManuelH wrote in the comment, static linkage is not allowed if your application is not free licensed either a LGPL or at least compatible to LGPL, nor do you use commercial license for Qt. It is better to make sure about this before picking up your approach.
Once that is done, you can use the
LIBS
variable in the regular way, as in: pass the path of your static library to it along with the library name, so something like this:Note that the static library name passed to the
-l
parameter should not contain the static library extension, for instance.lib
on Windows.As a fallback, you can always link other libraries statically, and put the Qt dll files beside the executable, and you deploy the folder as a "package". That is probably the easier way for you to go.