1

I was successfully able to compile and run my Qt application. However, when I move the .exe file outside its original path, I found out that I have to manually copy the Qt DLLs (e.g. mingw10.dll, qtcore4.dll). Is there any dynamic way to link these libraries with my application?

2 Answers2

4

I think you mean you want to "statically" link these libraries with your application. Basically this means that everything will be rolled inside your exe, and you will have no need of those dlls anymore.

There are advantages to to static linking, but there are also disadvantages as well. You should be absolutely sure that this is what you want to do before you go this way.

Check out this link which explains the difference in depth Dynamic Linking vs Static Linking

As for your specific issue, if you are sure you want to use static linking you will have to change your Qt setup to be built statically. By default the Qt distribution is setup to use dynamic linking. There is a handy guide for that here.

Basically when you setup the build you have to run "configure -static" to change all the project settings to use static linking instead of dynamic linking. And then build Qt over again.

You should also verify your Qt license. If you are using the Qt LGPL license and you want to to link statically you will have to include all your object files (.o and .obj) as Mihai Limbășan wisely explained in his comment. If you have bought and paid for Qt, then you have no problem.

Community
  • 1
  • 1
Liz
  • 8,257
  • 2
  • 34
  • 40
  • Static linking doesn't violate the LGPL as such, but you have to provide your app's .o / .obj files so that the end user can reconstruct a working executable by linking your object files with a different (compatible) Qt version. For more details, please see here: http://stackoverflow.com/questions/2945612/2946131#2946131 – Mihai Limbășan Nov 30 '10 at 20:15
  • That is why I said this is a contentious issue. :) – Liz Nov 30 '10 at 20:20
  • Not as much contentious, as poorly understood :) The LGPL is quite clear on the matter, it's just that nobody likes to read licenses (yours truly included.) – Mihai Limbășan Nov 30 '10 at 20:58
2

If the DLLs are on the PATH for the application, then they will be found and work. So, you could add where your Qt binaries/dlls are into the %PATH% environment variable. If you're going to create an installer for your application, you'll need to either package these libraries in so they're in the bin directory - or you'll have to expect every user to install and possibly compile Qt themselves (hint: go with the first option. :) )

TZHX
  • 4,707
  • 14
  • 43
  • 52