2

I've got a Qt application that I compile statically, i.e. in such a way that all the Qt DLLs are not needed at execution time.

However, my app still needs Microsoft's DLLs: specifically MSVCP100.DLL and MSVCR100.DLL. How can I compile my application so that these two DLL are not needed? Do I need to set some flag somewhere in .pro file? I'm a bit lost with Qt static compilation in general so any suggestion would be welcome.

laurent
  • 88,262
  • 77
  • 290
  • 428

3 Answers3

8

The problem is, that with Qt, a number of command line options are added before the command line options that come from the qmake variables. The solution is to remove these variables.

This did the trick for me:

QMAKE_CFLAGS_RELEASE += /MT
QMAKE_CXXFLAGS_RELEASE += /MT
QMAKE_CFLAGS_RELEASE -= -MD
QMAKE_CXXFLAGS_RELEASE -= -MD

The option you want to remove must match exactly. E.g. /MD and -MD are treated as different options.

0

Thanks to stijn to remind me of that... I forgot that the linker flag is in the compiler settings in MSVS, so I didn't find them and thought it wasn't possible...

However, these lines should do the trick, as they tell the linker to use the Multithreaded statically linked runtime libraries:

QMAKE_CFLAGS_RELEASE += /MT
QMAKE_CXXFLAGS_RELEASE += /MT
QMAKE_CFLAGS_DEBUG += /MTd
QMAKE_CXXFLAGS_DEBUG += /MTd
king_nak
  • 11,313
  • 33
  • 58
  • Please merge your two answers into one. – Piotr Dobrogost Mar 23 '11 at 19:59
  • 1
    This doesn't work. I get plenty of warnings such as "cl : Command line warning D9025 : overriding '/MD' with '/MT'" Then several "MSVCRT.lib(MSVCR100.dll) : error LNK2005: _somesymbol already defined in LIBCMT.lib(_ctype.obj)" I would know how to fix that in VC++ but I have no idea in Qt. – laurent Mar 24 '11 at 04:04
-1

You probabely won't be able to remove those dependencies, as these DLLs include the C/C++ runtime environment, like the STD functions and classes, and Windows specific functions (they further depend on kernel32.dll). So in order to remove those, you would require to statically link the entire C/C++ runtime and parts of the windows OS...

Anyway this won't matter, as these DLLs will be present on virtually every win pc out there.

king_nak
  • 11,313
  • 33
  • 58
  • 2
    statically linking just the runtimes should do fine (and is definitely possible). It doesn't matter if these depend on kernel32.dll etc: these are available on *ever* win pc, plus they don't even come with a static link option – stijn Mar 23 '11 at 15:08
  • 1
    Of course these dependencies can be removed - MSVCP100.DLL and MSVCR100.DLL are C++ libraries that are *not* present on most systems. They either need to be statically linked or provided with the exe. – laurent Mar 24 '11 at 04:01
  • This answer is wrong. You can link fully static exe with MSVC. – Pavel Strakhov Jun 11 '13 at 09:02