views:

957

answers:

4

I have a C++/MFC app on windows - dynamically linked it's only 60kb static it's > 3Mb.
It is a being distributed to customers by email and so needs to be as small as possible.

It statically links the MFC and MSCVRT libraries - because it is a fix to some problems and I don't want more support calls about missing libs - especially the very helpful 'application configuration is incorrect' one!

Is there anyway to strip a Windows exe of all the extra MFC stuff that is the dll but that I'm not using?
Or tell it to dynamically link MSVCRT (which must be present) but statically link the MFC dll which might not be?

Edit - thanks that got it down to 1.6Mb that will have to do!

A: 

going lean and mean might help you out.

EvilTeach
+5  A: 

You can't mix the CRT/MFC dlls. Going from memory...

As the other answer suggested, you can #define WIN32_LEAN_AND_MEAN and VC_EXTRALEAN. These probably won't help though. They tend to be about minimizing build time - not the final exe size.

Short of rebuilding MFC (Which is an option - you could rebuild it /Os, or if you are feeling really cheeky, /GL - but this will probably lead to more downstream fun - hopefully it's already built /Gy).

OK. Simple things to try. Build your app with /GL /Os /GF /Gy /GA. In the linker you more or less want /OPT:REF and /OPT:ICF and /LTCG.

I have to say - a release build from 30k to megabytes is a bit much. You could also pass /map: to the linker and see what's taking all that space - but that's very very tedius.

It almost sounds like MFC wasn't built with /Gy - but that would be surprising.

Joe
+5  A: 

I'm not sure how to strip the executable, but another thought is to compress it, for example using upx, which will decompress it and run it in place... Does that reduce the size enough for you?

Stobor
UPX is excellent, one of my apps is 6mb before and 2mb after upx!
KPexEA
A: 

You can try Dependency Walker to check which DLLs that your static EXE file depends on, then if it depends on a library you are certain it exists at your client's machine, you can compile without it and reduce the size.

Lawand