Solved

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

Posted on 2002-04-08
14
478 Views
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?

Thanks,
Frank
0
Comment
Question by:magenta
14 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 10 total points
Comment Utility
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
 

Author Comment

by:magenta
Comment Utility
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
 
LVL 3

Expert Comment

by:GGRUNDY
Comment Utility
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
 

Author Comment

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

Thanks,
Frank
0
 
LVL 3

Expert Comment

by:GGRUNDY
Comment Utility
0
 
LVL 1

Expert Comment

by:bluprint
Comment Utility
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
 
LVL 3

Expert Comment

by:DrMaltz
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:GGRUNDY
Comment Utility
0
 
LVL 5

Expert Comment

by:proskig
Comment Utility
>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
 

Author Comment

by:magenta
Comment Utility
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
 
LVL 11

Expert Comment

by:griessh
Comment Utility
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
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
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
 

Author Comment

by:magenta
Comment Utility
Moderator, please distribute the questions to everyone that answered.

Thanks,
Frank
0
 
LVL 6

Expert Comment

by:Mindphaser
Comment Utility
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

If your app took Google’s lash recently, here are the 5 most likely reasons.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now