减小 Windows 可执行文件大小
我在 Windows 上有一个 C++/MFC 应用程序 - 动态链接它只有 60kb 静态它 > 3Mb.
它是通过电子邮件分发给客户的,因此需要尽可能小.
I have a C++/MFC app on windows - dynamically linked it's only 60kb static it's > 3Mb.
It is a being distributed to customers by email and so needs to be as small as possible.
它静态链接 MFC 和 MSCVRT 库 - 因为它修复了一些问题,我不希望更多关于缺少库的支持电话 - 尤其是非常有用的应用程序配置不正确"!
It statically links the MFC and MSCVRT libraries - because it is a fix to some problems and I don't want more support calls about missing libs - especially the very helpful 'application configuration is incorrect' one!
有没有办法从 Windows exe 中删除所有额外的 MFC 内容,即 dll 但我没有使用这些内容?
或者告诉它动态链接MSVCRT(必须存在)但静态链接可能不存在的MFC dll?
Is there anyway to strip a Windows exe of all the extra MFC stuff that is the dll but that I'm not using?
Or tell it to dynamically link MSVCRT (which must be present) but statically link the MFC dll which might not be?
编辑 - 感谢您将它降低到 1.6Mb,这是必须要做的!
Edit - thanks that got it down to 1.6Mb that will have to do!
推荐答案
你不能混合 CRT/MFC dll.记忆中的...
You can't mix the CRT/MFC dlls. Going from memory...
正如其他答案所建议的,您可以#define WIN32_LEAN_AND_MEAN 和 VC_EXTRALEAN.不过,这些可能无济于事.它们往往是关于最小化构建时间 - 而不是最终的 exe 大小.
As the other answer suggested, you can #define WIN32_LEAN_AND_MEAN and VC_EXTRALEAN. These probably won't help though. They tend to be about minimizing build time - not the final exe size.
缺少重建 MFC(这是一个选项 - 你可以重建它/Os,或者如果你觉得很厚脸皮,/GL - 但这可能会带来更多下游乐趣 - 希望它已经构建/Gy).
Short of rebuilding MFC (Which is an option - you could rebuild it /Os, or if you are feeling really cheeky, /GL - but this will probably lead to more downstream fun - hopefully it's already built /Gy).
好的.简单的事情可以尝试.使用/GL/Os/GF/Gy/GA 构建您的应用程序.在链接器中,您或多或少需要/OPT:REF 和/OPT:ICF 和/LTCG.
OK. Simple things to try. Build your app with /GL /Os /GF /Gy /GA. In the linker you more or less want /OPT:REF and /OPT:ICF and /LTCG.
我不得不说 - 从 30k 到 MB 的发布版本有点多.您也可以将/map: 传递给链接器,看看是什么占用了所有空间 - 但这非常乏味.
I have to say - a release build from 30k to megabytes is a bit much. You could also pass /map: to the linker and see what's taking all that space - but that's very very tedius.
听起来好像 MFC 不是用/Gy 构建的 - 但这会令人惊讶.
It almost sounds like MFC wasn't built with /Gy - but that would be surprising.
相关文章