Click here to Skip to main content
13,449,970 members (52,566 online)
Click here to Skip to main content
Add your own
alternative version


61 bookmarked
Posted 7 Jun 2000

Reduce the Size of Your Final EXE File

, 7 Jun 2000
Rate this:
Please Sign up or sign in to vote.
This article describes ways to reduce the final size of your applucation's EXE file.
  • Download unchanged project - 16K
  • Download project reduced with these techniques - 9K


    A few days back I was assigned a challenging task of writing a Win32 application performing tasks (as defined by our client). But the client required that the final exe file size to be less than 50K. With this kind of size limit we immediately had to give up an MFC based solution, a tough decision to make in most cases :). I am very comfortable with MFC and never had bothered about final file size. But for this specific project I had to dig into pure Win32 SDK to get things done. The project was started and the first prototype was sized about 36K and everyone was happy. But problems were raised when we started implementing the user requirements and one day we found that the size of the exe file in release mode had exceeded the 50K limit. And when the final product was about to be shipped the size had reached about 72K. We were thinking about re-nagotiating the size limit with our client. Fortunately I posted a question on one of the Microsoft news threads and got some prompt replies. I tried to test the instructions that I received from the news thread on my application, and the result were simply amazing, my file size reduced to 35K resulting in about 50% files size reduction. We were happy and so was our client :)

    So what are those magic tricks? Actually all you have to do is to instruct compiler to leave out unnecessary code from your application. If you create a simple HelloWorld Win32 Application from the app wizard and compile it in release mode, the resulting exe file size is 24K. Too much for a simple "Hello World" application. Now, perform the following steps:

    1. Create another similar project workspace, i.e. another "Hello World" project.

    2. Select active build configuration to be "Win32 Release".

    3. Open project setting and select the "Link" tab. Remove all the library file names from the "Object/library modules:" edit box and type "MSVCRT.LIB kernel32.lib user32.lib". Press OK and compile, the final exe file size is reduced to 16K. You might get a linker warning like "LINK : warning LNK4098: default lib "LIBC" conflicts with use of other libs; use /NODEFAULTLIB:library". This can be avoided by clicking "Ignore all default libraries" from the Link tab of Project Settings.

    4. The further magic is done by using /ALIGN linker option. You can see MSDN for further details about this linker option. Again go to the "Project Settings", "Link" tab. Type /ALIGN:4096 in the Project Options edit box. Press OK and rebuild your project. The size is further reduced to 3K. The compiler generates a linker warning "LINK : warning LNK4108: /ALIGN specified without /DRIVER or /VXD; image may not run". If you have followed my instructions properly, your exe file should run properly. I played around with the /ALIGN linker directive and figured out that if you use /ALIGN:4096 the produced exe file runs properly.

    That's it, we have reduced size of our Hello World app from 24K to 3K. There are some other options that you can try in this regard:

    1. You can run some symbol stripper utility on the final exe file. It helps reducing size in many cases. One such utility can be found at

    2. There is a utility named ASPack, this utility also helps in compressing your exe files up to 50%.


    I haven't yet tried these tricks with MFC projects, so results are unpredictable. But that should not stop you from trying these options on MFC projects.

  • License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    Rehan Nadeem
    Bahrain Bahrain
    No Biography provided

    You may also be interested in...


    Comments and Discussions

    Generalnice Pin
    cute_friend70771-Feb-10 22:21
    membercute_friend70771-Feb-10 22:21 
    GeneralMerge Sections... Pin
    st0le18-Feb-08 18:56
    memberst0le18-Feb-08 18:56 
    General/align:4096 Pin
    |[awx]|29-Jun-05 2:38
    member|[awx]|29-Jun-05 2:38 
    GeneralAggressive Optimizations for Visual C++ Pin
    Armen Hakobyan20-Apr-05 21:58
    memberArmen Hakobyan20-Apr-05 21:58 
    QuestionHow does /Align option affects exe loading time Pin
    Chong Wu16-Apr-05 17:45
    memberChong Wu16-Apr-05 17:45 
    GeneralSome improvemennts... Pin
    slowweb18-Jan-05 3:46
    memberslowweb18-Jan-05 3:46 
    Generalvs2002 Pin
    ftai26-May-04 19:11
    memberftai26-May-04 19:11 
    QuestionMSVCRT.DLL? Pin
    CzarTJ23-Aug-03 18:08
    memberCzarTJ23-Aug-03 18:08 
    QuestionUse with DLLs? Pin
    Sebastian Pipping14-Aug-03 7:25
    memberSebastian Pipping14-Aug-03 7:25 
    GeneralThanks a lot. Pin
    Tili26-Nov-02 2:43
    memberTili26-Nov-02 2:43 
    GeneralIt doesn't work! Pin
    Mazdak7-Feb-02 12:20
    memberMazdak7-Feb-02 12:20 
    GeneralRe: It doesn't work! Pin
    Rehan Nadeem8-Feb-02 23:54
    memberRehan Nadeem8-Feb-02 23:54 
    GeneralRe: It doesn't work! Pin
    Anthony_Yio22-Oct-02 16:07
    memberAnthony_Yio22-Oct-02 16:07 
    GeneralRehan Nadeem see this Pin
    Mazdak5-Feb-02 10:24
    memberMazdak5-Feb-02 10:24 
    GeneralVC7 Pin
    Mazdak5-Feb-02 10:21
    memberMazdak5-Feb-02 10:21 
    GeneralEXE compressors Pin
    Bjornar Henden10-Jun-00 5:36
    sussBjornar Henden10-Jun-00 5:36 
    GeneralTesting with various linker opts Pin
    Todd Wilson9-Jun-00 5:15
    sussTodd Wilson9-Jun-00 5:15 
    GeneralComments... Pin
    Todd Wilson8-Jun-00 8:53
    sussTodd Wilson8-Jun-00 8:53 
    GeneralRe: Comments... Pin
    Alan Fritz8-Jun-00 15:10
    sussAlan Fritz8-Jun-00 15:10 
    GeneralRe: Comments... Pin
    Todd Wilson9-Jun-00 5:16
    sussTodd Wilson9-Jun-00 5:16 
    GeneralRe: Comments... Pin
    Rehan9-Jun-00 21:37
    sussRehan9-Jun-00 21:37 
    GeneralUPX: a compression tool Pin
    Josef Haslinger8-Jun-00 1:49
    sussJosef Haslinger8-Jun-00 1:49 
    GeneralRe: UPX: a compression tool Pin
    Balkrishna Talele6-Jan-06 20:05
    memberBalkrishna Talele6-Jan-06 20:05 
    GeneralRe: UPX: a compression tool Pin
    Josef Haslinger7-Jan-06 21:32
    memberJosef Haslinger7-Jan-06 21:32 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web03-2016 | 2.8.180318.3 | Last Updated 8 Jun 2000
    Article Copyright 2000 by Rehan Nadeem
    Everything else Copyright © CodeProject, 1999-2018
    Layout: fixed | fluid