可执行文件(基于MFC对话框的应用程序)VS2010的大小 [英] Size of Executable (MFC dialog based application) VS2010

查看:120
本文介绍了可执行文件(基于MFC对话框的应用程序)VS2010的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于MFC对话框的应用程序上工作,但是当我静态链接dll时,在释放"模式下可执行文件的大小很大.我用它搜索了一下,并在此链接中找到了一个解决方案解决方案

您在项目属性中有两个地方可以设置可能影响可执行文件大小的设置:


    C/C ++ 部分的 Optimization 小节下:有两个设置,第一个是 Optimization ,默认设置是最大化速度(/O2),您可以将其更改为最小化尺寸(/O1).第二个是收藏夹大小或速度,其默认值为都不是,您可以将其更改为收藏夹小代码(/Os).
  1. Linker 部分的 Optimization 小节下:有两个设置,第一个是 References ,您应确保将其设置为消除未引用的数据(/OPT:REF).第二个是启用COMDAT折叠,您应该确保将其设置为删除冗余COMDAT(/OPT:ICF).

.我认为有一个编译器选项可以优化大小,这可能会有所不同.还要确保您具有发布版本,并链接到发布mfc库(名称末尾没有d的库).

您的exe太大的主要原因是您正在使用的所有mfc库都是静态包含在exe中的.如果动态链接,您的exe会小很多,但您需要分发使用的mfc dll.


升级到VS2010时,我遇到了同样的问题.您的对话框是从CDialogEx派生的吗?如果是这样...删除所有对CDialogEx的引用,而是从CDialog派生您的对话框,您的可执行文件大小将急剧下降.由Visual Studio 2010功能包"标头引起的MFC可执行文件大小异常,这些标头包括一个bazilliontrillion不必要的其他标头和库,这些标头和库将链接到您的二进制文件中.

最好的祝福,
-大卫·德劳恩(David Delaune)


I am working on MFC dialog based application but the size of executable in Release mode when i statically linked the dll is very large. I googled it and found one solution in this link Click here->[^].I tried this solution but it is not reducing the size of dialog based application.

Can anyone have solution of this problem??

Thanks in advance :)

解决方案

You have two places in the project propertiess where to set-up settings that could affect the executable size:


  1. under the Optimization subsection of C/C++ section: there are two settings, the first one is Optimization, its default is Maximize Speed (/O2), and you could change it to Minimize Size (/O1). The second one is Favor Size or Speed, its default is Neither, and you could change it to Favor Small Code (/Os).
  2. under the Optimization subsection of Linker section: there are two settings, the first one is References, and you should ensure to set it to Eliminate Unreferenced Data (/OPT:REF). The second one is Enable COMDAT Folding, and you should ensure to set it to Remove Reduntant COMDATs (/OPT:ICF).


I think there is a compiler option to optimise for size which may make a small difference. Also ensure you have a release build and are linking to the release mfc libs (the ones without a d at the end of the name).

The main reason your exe is so large is all the mfc libs you are usinging are statically included in your exe. If you dynamically link your exe will be much smaller but you will need to distribute the mfc dlls you use.


I had the same problem when I upgraded to VS2010. Are your dialogs derived from CDialogEx? If so...remove all references to CDialogEx and instead derive your dialog from CDialog and your executable size will drop dramatically. There is abnormal MFC executable size caused by the Visual Studio 2010 "Feature Pack" headers which include a bazilliontrillion unneccesary other headers and libs which will be linked into your binary.

Best Wishes,
-David Delaune


这篇关于可执行文件(基于MFC对话框的应用程序)VS2010的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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