• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 497
  • Last Modified:

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

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?

1 Solution
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?
magentaAuthor Commented:
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.

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.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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

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'
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,

>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:

magentaAuthor Commented:
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?! ;)

You can always post a 0 point question in Community Support at http://www.experts-exchange.com/commspt/ to split the points between the experts taht helped you. Just tell them the URL of this question (http://www.experts-exchange.com/cplusprog/Q.20286253.html) and the names of the experts who are supposed to receive points and one of the nice moderators will take care of it.

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.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

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
magentaAuthor Commented:
Moderator, please distribute the questions to everyone that answered.

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 **
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now