如何编译 Qt 应用程序以便不需要 Microsoft 的 dll?
我有一个静态编译的 Qt 应用程序,即在执行时不需要所有 Qt DLL。
但是,我的应用程序仍然需要 Microsoft 的 DLL:特别是 MSVCP100.DLL 和 MSVCR100.DLL。如何编译我的应用程序以便不需要这两个 DLL?我需要在 .pro 文件中的某个位置设置一些标志吗?一般来说,我对 Qt 静态编译有点迷茫,所以欢迎任何建议。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是,对于 Qt,在来自 qmake 变量的命令行选项之前添加了许多命令行选项。解决方案是删除这些变量。
这对我来说很有效:
您要删除的选项必须完全匹配。例如,
/MD
和-MD
被视为不同选项。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:
The option you want to remove must match exactly. E.g.
/MD
and-MD
are treated as different options.感谢 stijn 提醒我这一点...我忘记了链接器标志位于 MSVS 的编译器设置中,所以我没有找到它们并认为这是不可能的...
但是,这些行应该可以解决问题,因为它们告诉链接器使用多线程静态链接运行时库:
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:
您可能无法删除这些依赖项,因为这些 DLL 包括 C/C++ 运行时环境,如 STD 函数和类,以及 Windows 特定函数(它们进一步依赖于 kernel32.dll)。因此,为了删除这些,您需要静态链接整个 C/C++ 运行时和部分 Windows 操作系统...
无论如何,这并不重要,因为这些 DLL 几乎存在于每台 win 电脑上。
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.