How to make VC++ generate the smallest possible executable binary?

Posted on 2002-04-08
Last Modified: 2013-11-15
Short of removing or rewriting code, is there any way to make VC++ to generate the smallest possible binary executable?

Since I am not using any MFC in my code, I've added the compile flag "WIN32_LEAN_AND_MEAN", but it had no effect.

Any other suggestions?

Question by:magenta
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 32

Accepted Solution

jhance earned 10 total points
ID: 6926526
Basically the answer is no.  MFC is only pulled into your code if you use it.  What you have is mostly LIBRARY code.  Even a simple program like:

  printf("This is a test\n");

uses a very large amount of code.  The printf() function is amazingly complex.  By careful choice of library functions you use you can greatly reduce the code size.

What is your purpose here anyway?  Under Windows code size of hardly an issue anymore.  Today's MINIMUM system RAM is 128MB RAM with 20GB+ hard drives.  So what's to be gained by scanvenging a few bytes?

Author Comment

ID: 6926533
So there are no compiler flags or anything like that that might reduce binary size?

I seem to remember that on Unix you could "strip" binaries of string data to reduce binary size. Is there something similar for Windows binaries?

By the way, for this project, the binary is download over the web so I want to keep it as small as possible.


Expert Comment

ID: 6926537
One thing to consider is the /opt:nowin98 option.
For some small exe's the effect can be quite dramatic.
But it is to some extent illusary because it doesn't affect the in-memory size, and if the modem is using any sort of compression probably won't affect download times either. About the only thing you can say for sure is that nowin98 can affect the on-disk size.

I assume you are already using the /O1 (Minimize Size) compiler switch.

Also dramatic and real reductions in code size can be obtained in simple exe's if you can avoid the use of the C runtime library. You will probably need to write your own malloc & free routines and avoid 'printf' and its ilk as well as eschewing the use of constructors in global & static objects. - but it can be worth it if you are REALLY concerned about size. Have a look at the way ATL uses the _ALT_MIN_CRT option.
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now


Author Comment

ID: 6926557
Forgot about "/O1"! This option made a big difference but I'm curious if there are any other options...


Expert Comment

ID: 6926603

Expert Comment

ID: 6927168
Look under the 'Project->settings' menu, select the c/c++ tab.

Look at the drop down menu titled "Optimizations", there s an option to "Debug", or "Maximize speed" or "minimize size"...

Look at those options and see if there is anything that works for you..

Also, on the left side of that box that comes up under 'Project->Settings', there is a drop down menu titled 'Settings For' and if you open that drop down menu, you can set it as 'Release' or 'Debug'...

I once had a project that we were having problems with. It took about 7 to 8 hours for the program to get to the point (in the data) that it would fail.

We added some error checking code, and someone realized that we had not changed that setting back to 'Release'. Since it was on 'Debug' we changed it to 'Release' and it ran in about 45 minutes (from 7+ hours). Anyway....just a lesson I hope other people dont have to learn the hard way. So if you want better performance, remember to change that to 'Release' instead of 'Debug'

Expert Comment

ID: 6927254
There was a great article written by Matt Peitrek called "Remove Fatty Deposits from Your Applications Using Our 32-Bit Liposuction Tools"

He provides some good pointers in what you should eliminate from your code as you're developing.  Hope this helps.

Good Luck,


Expert Comment

ID: 6927288

Expert Comment

ID: 6928972
>There was a great article written by Matt Peitrek called "Remove Fatty Deposits from Your Applications
Using Our 32-Bit Liposuction Tools"

There is new article by Matt Pietrek:

Author Comment

ID: 6929118
Wow, thanks for all the cool articles---there's more than enough here for me to literally squeeze out some bytes!

Ok, problem now is, who gets the points?! ;)
LVL 11

Expert Comment

ID: 6960626

You can always post a 0 point question in Community Support at to split the points between the experts taht helped you. Just tell them the URL of this question ( and the names of the experts who are supposed to receive points and one of the nice moderators will take care of it.


Expert Comment

ID: 6979413
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.

To view your locked questions, please click the following link(s) and evaluate the proposed answer.

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link 
POINTS FOR EXPERTS awaiting comments are listed in the link below
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moderator @ Experts Exchange

Author Comment

ID: 6979662
Moderator, please distribute the questions to everyone that answered.


Expert Comment

ID: 6981110
Per request I will split the 50 pts between proskig GGRUNDY DrMaltz bkuprint jhance.

Thanks everybody for your help. You will find a separate question with your points.

** Mindphaser - Community Support Moderator **

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
A list of useful business intelligence software.
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question