Reduce exe file size

This is a discussion on Reduce exe file size within the C Programming forums, part of the General Programming Boards category; does anybody know how to reduce the size of an exe file Thanks....

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    19

    Reduce exe file size

    does anybody know how to reduce the size of an exe file

    Thanks.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you're asking literally, how to reduce the size of an exe file, and I presume you still want it to work, then the answer is no, I don't. That's like asking to change the size of the steer, when you hold it's meat in a lump of hamburger.

    If you mean change the program that created the exe file, so it's making a smaller exe file, then yes, you have several options.

    First and foremost would be to reduce the number of include files. The changes needed to do this, while keeping the program working, may be small or large. Great care must be taken, and thorough testing afterward is essential.

    How large is this exe file, anyway? What size do you want it to be? Is it coded with an efficient algorithm?

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    1. you can strip the symbol stuff out gcc -s main.c
    2. compile for size gcc -Os main.c

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You could use an executable packer like UPX. UPX is really neat. It compresses your executable. When you go to run your program, it decompresses it in memory. It's incredibly fast. You probably wouldn't notice the delay in startup time at all. UPX is available here: http://upx.sourceforge.net/

    First and foremost would be to reduce the number of include files. The changes needed to do this, while keeping the program working, may be small or large. Great care must be taken, and thorough testing afterward is essential.
    Reducing the number of include files won't decrease the size of the executable. It might reduce compile time, but the size of the resulting executable is completely independent of which header file were included.

    You could reduce the number of libraries used, but generally if you're using a library it's important.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    > First and foremost would be to reduce the number of include files.
    This seldom has anything to do with the size of the executable. Header files contain declarations only, they do not take up actual code space.

    You might see the size grow because of additional symbol table information, but that would be removed if you follow robwhit's comments on 'strip' (which is also available as a separate command).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. Error with a vector
    By Tropicalia in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2006, 07:45 PM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  5. Replies: 11
    Last Post: 03-25-2003, 04:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21