减少Windows可执行文件大小 [英] Reduce windows executable size

查看:159
本文介绍了减少Windows可执行文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上有一个C ++ / MFC应用程序 - 动态链接它只有60kb静态它> 3Mb。

它是通过电子邮件分发给客户,因此需要尽可能小。



它静态链接MFC和MSCVRT库 - 因为它是一些问题的修复,我不想要更多的关于缺少lib的支持调用 - 特别是非常有用的'应用程序配置不正确'一个!



有没有办法剥离一个Windows exe的所有额外的MFC的东西是dll,但我没有使用? >
或者告诉它动态地链接MSVCRT(必须存在),但静态链接可能不是的MFC DLL?



编辑 - 感谢你得到它下降到1.6Mb,这将不得不做!

解决方案

你不能混合CRT / MFC DLL。从内存中...



正如其他答案建议的那样,您可以#define WIN32_LEAN_AND_MEAN和VC_EXTRALEAN。这些可能不会帮助。他们往往是最小化构建时间 - 而不是最终的exe大小。



重建MFC不够(这是一个选项 - 你可以重建它/ Os,或者如果你感觉真的很厚重,但是这可能会导致更多的下游乐趣 - 希望它已经建成/ Gy)。



好的。简单的事情要尝试。使用/ GL / Os / GF / Gy / GA构建您的应用程序。在链接器中,你或多或少想要/ OPT:REF和/ OPT:ICF和/ LTCG。



我不得不说 - 从30k到兆字节的发行版本有点多。你也可以传递/映射到链接器,看看占用了所有的空间 - 但是这非常非常tedius。



几乎听起来像MFC没有用/ Gy - 但这会令人惊讶。


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.

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!

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?

Edit - thanks that got it down to 1.6Mb that will have to do!

解决方案

You can't mix the CRT/MFC dlls. Going from memory...

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.

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).

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.

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.

It almost sounds like MFC wasn't built with /Gy - but that would be surprising.

这篇关于减少Windows可执行文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆