4

I've got a Qt project I've built in Visual Studio 2010 Professional. However, when I run it (in either Debug or Release mode) it asks for a few Qt dll's. It works if I supply the dll's and throw them into System32, but my question is, how do I make it so that all libraries are included in the .exe? I have all of the static libraries I need, I just don't know how to make it so that the app doesn't ask the end user for them.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
DMK741
  • 43
  • 1
  • 3

1 Answers1

6

The correct way is to create a setup program that installs the Qt libraries along with your application. Visual Studio comes with a setup project template that you can use to create your own customized installer easily. Static linking is rarely a good option, for numerous reasons.

However, if you insist on static linking, you'll need to recompile the Qt sources with the -static flag.
A walkthrough is available here for Qt 4.

And if you're using the LGPL version of Qt, make sure you've read the answers to this question and appropriate addressed all legal concerns with your deployment.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • I do wonder though, how would I configure things so that only a few libraries would be linked statically, and the rest (libraries that would likely need updates/fixes in the future) would be linked dynamically? – DMK741 Apr 17 '11 at 08:58
  • @user: I'm pretty sure that's not possible. You either get all of the Qt libraries along for the ride, or not. You can statically link the Qt libraries, but *not* Microsoft's C/C++ runtime libraries (or vice versa). But I'm not sure why you'd want to. If your goal is to eliminate all dependencies and ship a single EXE, then static linking is your only option. If you're willing to have *some* dependencies, then you really should just build an installer and ship *that* as your single EXE. It's one extra step for the user, but it really reduces headaches! – Cody Gray - on strike Apr 17 '11 at 09:08
  • A bit off-topic, but I wonder why is static linking not a good option? I can't find much about this on Google and I'd like to know so that I can convince my clients to forget about static linking (which is always a nightmare with Qt). – laurent Apr 17 '11 at 09:09
  • @Laurent: Hrmm, I can think of several disadvantages, but *very* few (if any) would be persuasive to a client. Ideally, the relationship is good enough that they trust your judgement as a developer, and go along with your recommendations. Barring that, I can think of two different options. First is to scare them with the argument that static linking prevents them from getting security updates when they are released for the runtime libs. When the app is statically linked, you have to release a whole new version, and deploy it to all client machines, in order to take advantage of any... – Cody Gray - on strike Apr 17 '11 at 09:13
  • security improvements that may have been made to the latest version of the library. Whereas the new versions of the runtime libraries are much smaller, can be deployed independently, and are often pushed by Windows Update (not the case for Qt, of course). The second route (and this is my favorite) is showing them how easy it is to create an installer. Inno Setup is my personal favorite solution, but VS has this built-in as well. You can create a setup program that amounts to a single EXE, just as easy to deploy as a single EXE app. All the user has to do is click Install. – Cody Gray - on strike Apr 17 '11 at 09:15