• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • 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?

Thanks,
Frank
0
magenta
Asked:
magenta
1 Solution
 
jhanceCommented:
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:

main()
{
  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?
0
 
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.

Thanks,
Frank
0
 
GGRUNDYCommented:
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

Thanks,
Frank
0
 
GGRUNDYCommented:
0
 
bluprintCommented:
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'
0
 
DrMaltzCommented:
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.

http://www.microsoft.com/msj/defaulttop.asp?page=/msj/archive/S572.htm

Good Luck,

DrMaltz
0
 
proskigCommented:
>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:

http://www.msdn.microsoft.com/msdnmag/issues/01/01/hood/hood0101.asp
0
 
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?! ;)
0
 
griesshCommented:
magenta

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.

======
Werner
0
 
MoondancerCommented:
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.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
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.
http://www.experts-exchange.com/questions/Q.20115902.html
http://www.experts-exchange.com/questions/Q.20123776.html
http://www.experts-exchange.com/questions/Q.20184557.html
http://www.experts-exchange.com/questions/Q.20192504.html
http://www.experts-exchange.com/questions/Q.20245395.html
http://www.experts-exchange.com/questions/Q.20254214.html
http://www.experts-exchange.com/questions/Q.20271357.html
http://www.experts-exchange.com/questions/Q.20279551.html
http://www.experts-exchange.com/questions/Q.20286253.html
http://www.experts-exchange.com/questions/Q.20291661.html
http://www.experts-exchange.com/questions/Q.20294731.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20286299.html

*****  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
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
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.
Moondancer
Moderator @ Experts Exchange
0
 
magentaAuthor Commented:
Moderator, please distribute the questions to everyone that answered.

Thanks,
Frank
0
 
MindphaserCommented:
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 **
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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