Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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 :)
Posted
Updated 24-Nov-10 20:19pm
v2

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).
 
Share this answer
 
Comments
ShilpiP 25-Nov-10 5:16am    
Hi Sauro Viti,
Thanks for ur reply.
I did the same but the size is reduced from 1.61 mb to 1.60 mb.
Sauro Viti 25-Nov-10 5:30am    
I'm sorry, but be aware that MFC is a quite huge and intrusive framework: to get a statically linked executable of 1.60 MB is not a bad result... If you really need a very small footprint you should consider using a different approach. You could try the WTL (Windows Template Library): its based on ATL and share a quantity of classes with MFC (like CString, CList, CMap, etc.).
Porting your application to WTL could require a while, but the result in terms of size will be great.
ShilpiP 25-Nov-10 5:39am    
Hi Thanks again,
Yae i know but the size of executable can be reduced up to 600 to 700 kb.The URL that i have given with my question does the same but i am not succeeded :(. something is missing :(
If i dont found any solution than i work on alternate solution obviously :)
Thanks :)
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.
 
Share this answer
 
Comments
ShilpiP 25-Nov-10 4:43am    
Hi ARopo,
Thanks for your reply. but it is not a feasible solution to distribute mfc dll.
Do you know the compiler option mentioned in your answer??
ARopo 25-Nov-10 12:18pm    
/01

Under project properties c/c++-optimization-Optimization Minimum Size(/o1)
ARopo 25-Nov-10 12:20pm    
Also Favor Size or Speed Favor small(/Os)
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
 
Share this answer
 
Comments
ShilpiP 25-Nov-10 13:31pm    
Hi thanks for ur reply .. but this i already did but the size remains same :(( please check the link that i had given with my question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900