-3

I want my Qt apps to run regardless of Qt-Specific DLLs. To do this, I should link the executable statically. That, however, requires a "static" installation of Qt itself.

This is where I'm stuck. I've browsed dozens of various tutorial pages, but they are either incompatible with my setup, poorly written or just plain wrong.

This is my situation:

  • Win 7, 32-bit
  • I've installed Qt (MSVC 2013 version), downloaded here: http://qt-project.org/downloads (Qt 5.3.1 for Windows 32-bit (VS 2013, 559 MB))
  • QtCreator works fine, I'm able to develop Qt Apps, but as said before, they are dynamically linked
  • It probably doesn't matter, but I have the Visual Studio addon version 1.2.3
  • I've also manually installed MinGW some time ago (not using the Qt installer)


Again, my goal is as follows: use QtCreator to compile statically linked exes that do not require Qt DLLs to be present to run.

Could anyone recommend a tutorial/wiki page describing the steps I should take?

user4520
  • 3,401
  • 1
  • 27
  • 50
  • another statically linked Qt question. You have failed the first prerequisite : static version of Qt. Rather than downloading and installing Qt, download the sources and compile with a compiler compatible with your app (ie msvc2013) with the appropriate flags. at least -static should be in configure. – UmNyobe Aug 12 '14 at 09:13
  • I'm aware this question has been asked many times, but as stated in my questions, the solutions did not work for me. I was merely asking for some platform-specific advice. The question that supposedly already has my answer actually doesn't, I've seen it before. – user4520 Aug 12 '14 at 10:18
  • can you specify how they are incompatible with your setup? That wiki has everything, even an environment script you can just copy, paste and execute. – UmNyobe Aug 12 '14 at 11:56
  • @UmNyobe I've tried that script before, PowerShell gave me strange error messages, I looked into it, found that this was a rare issue vaguely described in some pages. I'm surprised how difficult it is for a QT newbie like me to achieve something as basic and elementary as compiling standalone EXEs. I've finally managed to compile my own version with MinGW, but not before solving two another bugs which, luckily, were described here @ stackoverflow. – user4520 Aug 12 '14 at 12:07
  • Also, Qt is renowned for its exceptional flexibility and ease of use. If so, then why is it so difficult to produce an independent version of your app? And why does it require you to recompile everything on your own? I mean, it's standard functionality. What's the point of coding a program, regardless of how good it is, when you can't distribute it and provide portability? There's some logic missing here, or I'm unaware of something. – user4520 Aug 12 '14 at 12:11
  • unfortunately compiling some libraries from source is not that "basic". It is better, as a starting point to say that you followed the steps at [Building Qt Desktop for MSCV](https://qt-project.org/wiki/Building_Qt_Desktop_for_Windows_with_MSVC) and you are stuck because you have problem `XXX`. where XXX is the exact error from the script. – UmNyobe Aug 12 '14 at 12:12
  • 1
    A vast majority use a dynamic version downloaded from the website and are fine with it. [It is very hard to distribute a static library](http://stackoverflow.com/a/18024808/1122645) on windows. Even less provide portability of a static library. – UmNyobe Aug 12 '14 at 12:20
  • @UmNyobe Hold on. Right now, when I compile my Qt app, it won't run outside QtCreator (as in, double clicking the exe) because "SomeFile.dll is missing, reinstall to fix" (unless I edit the PATH variable). Are you telling me this is normal? I can't expect users of my programs to have the Qt SDK installed. Am I missing something? – user4520 Aug 12 '14 at 15:01
  • this is a different question. see http://stackoverflow.com/a/14703874/1122645 – UmNyobe Aug 12 '14 at 15:29

2 Answers2

0

What you need, are Qt-Libs that can be linked statically and are not stubs for a DLL. i found a number of references by googleing on the spot:

How to build a static Qt version for Windows with GCC

Building static libraries

Both are using GCC, but it should be possible to build with MSVC as well.

Community
  • 1
  • 1
RED SOFT ADAIR
  • 12,032
  • 10
  • 54
  • 92
  • there are literally thousands of questions on SO. – UmNyobe Aug 12 '14 at 09:15
  • 1
    As long as my answer is not incorrect, it would be nice to refrain from downvoting. – RED SOFT ADAIR Aug 12 '14 at 09:31
  • I downvoted because the OP is saying that his question is different while it is a pretty standard setup, and there are multiple questions addressing this problem. Furthermore, you just posted "on the spot" with links related to GCC. *"it should be possible with MSVC"* is not a correct answer imho. – UmNyobe Aug 12 '14 at 12:02
0

I've finally figured it out, it did, however, take me the whole day to do it.

Qt 5.2.1 is riddled with bugs when it comes to building the source (or so I've read somewhere). I had multiple compilation issues with it, most of which was fixable after digging in the internet for a couple of minutes (editing various heading files, tampering with macros), but given a compilation time of > 2h on my Compaq trying and hoping that it would work was just too much.

Luckily, somewhere I've stumbled upon a suggestion to use 4.8.6 instead. Well, I downloaded that version, compiled it with win32-msvc2013, added to QtCreator and it works fine.

Note: while compiling 4.8.6, GCC might fail complaining about off64_t being undefined. This seems to be a MinGW bug, unrelated to Qt. The issue and solution are described here: Static compilation of Qt 5 fails under mingw with reference to off64_t

I must say, I truly do not understand this situation. Qt is a very powerful and popular framework. Being able to develop standalone, independent exes that do not require the user to install anything more than Windows is a basic requirement and should be a child's play, and yet it is so time-consuming and difficult.

The reason why I've asked this question in the first place is that none of the pages I've found (and that were suggested here as answers) seemed to work for me.

Community
  • 1
  • 1
user4520
  • 3,401
  • 1
  • 27
  • 50