How to compile a Qt app so that Microsoft's dll are not needed? [duplicate]
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.
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.
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
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.
精彩评论