Results 1 to 26 of 26

Thread: 500 KB exe???

  1. #1
    Sc0rp
    Guest

    Thumbs down 500 KB exe???

    I just compiled a simple console program in C++.

    These are the includes:
    PHP Code:
    #include <vector>
    #include <iostream>
    #include <conio.h>

    using std::vector;
    using std::cout;
    using std::cin;
    using std::endl
    The program is not more than 150 lines, I compiled it and I got a 528 KB exe!?! What the!?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Make sure you have compiled it in release mode (not debug mode). Go to the Build Menu -> SetActiveConfiguration and make sure what is chosen.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Sc0rp
    Guest
    Thanks, that reduced it to 116 KB.

    But isn't that a little large too?

  4. #4
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    yeah that's pretty big!

    My checkers game (about 500 lines) is 36 kilobytes...take a look for yourself!
    Attached Files Attached Files

  5. #5
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    sorry...that was a pretty blatent ad! hehehe

  6. #6
    Sc0rp
    Guest
    Was that made using C++?

    If it was then how come my small console app takes 3 times the space your checkers take?

  7. #7
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    maybe it's just that your header files take up the space I only had a few...you have a lot more.

  8. #8
    ChimpFace9000
    Guest
    I wrote an entire Windows app in C that came out in 1kb. It used Win16 techniques. If i could remeber how, id show ya, but i dont rememebr.

  9. #9
    Sc0rp
    Guest
    1K ???!!!!?!?!?

    I compiled this:
    PHP Code:
    int main()
    {
        return 
    0;

    This turned out 24K compiled!!! AAAHHH!!!

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Take out all the run-time library link statements in Project Settings, write your own _mainCRTStartup function, and see just how small it goes. I'll have a pop and see how I do...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    2.5KB program file anyone?
    Code:
    /* tiny.c */
    #include <windows.h>
    
    void __cdecl WinMainCRTStartup(void) {
        MessageBox(NULL, "Hello", "Hello", MB_OK);
    
        ExitProcess(0);
    }
    Compile optimised for size (in Release mode, obviously )

    Link ignoring default libraries, and take everything except for kernel32.lib and user32.lib out of the list
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    Sc0rp
    Guest

    Thumbs up Thanks parksie!

    That helped a lot!

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Read this as well, because I just managed to kick my system squarely up the backside by using some non-initialised functions

    http://www.microsoft.com/msj/default...chive/S569.htm
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  14. #14
    Sc0rp
    Guest

    Thumbs up

    Thanks everybody!
    Vlatko, SteveCRM, ChimpFace9000.

  15. #15
    Sc0rp
    Guest
    Parksie:

    Originally posted by MSDN Journal
    ...on most hard drives the minimum space that a file takes up is 8KB or 16KB. Thus (as the logic goes), it's not worth trying to make your programs smaller than 8KB.
    Good effort anyway.

  16. #16
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    More space for fancy graphics

    And since mine was only a one-liner
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  17. #17
    denniswrenn
    Guest
    Originally posted by parksie
    2.5KB program file anyone?
    Code:
    /* tiny.c */
    #include <windows.h>
    
    void __cdecl WinMainCRTStartup(void) {
        MessageBox(NULL, "Hello", "Hello", MB_OK);
    
        ExitProcess(0);
    }
    Compile optimised for size (in Release mode, obviously )

    Link ignoring default libraries, and take everything except for kernel32.lib and user32.lib out of the list
    Wouldn't it be smaller if you #define'd WIN32_LEAN_AND_MEAN ?

  18. #18
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Nope
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  19. #19
    denniswrenn
    Guest
    Why not?

  20. #20
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    I think that just speeds up compiling, but doesn't make the .exe any smaller.
    Alcohol & calculus don't mix.
    Never drink & derive.

  21. #21
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    The linker excludes most things that aren't actually necessary, code-wise. However, the RTL startup code pulls in a lot of extra functions, bulking up the EXE.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  22. #22
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340

    hate to bring up an old thread but...

    i am making a simple program, in release mode, and i am still getting a 162 kb exe! i took out all those extra libs like parksie said, and that didn't make any difference. i can't ignore default librarys, becuase i get errors.

    My friend made the same program in C, and it was 44kb. Does anyone have any tips for making it smaller? perhaps a different compiler?

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  23. #23
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    C++ programs are always bigger than C programs.

    If you write in C then because there is less compiler-generated code (for handling virtual functions, static constructors, etc.) you can replace a large proportion of the startup code with something smaller.

    You could always try compressing it (120K->50K) - search for UPX (I use that )
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  24. #24
    amac
    Guest
    Read this...

    http://www.hailstorm.net/papers/smallwin32.htm

    It should help...

  25. #25
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80
    Wow that is strange... THIS came to 24k:

    int main() {}

    Thats the only line in there... not even a #include...
    Do you know if you will answer no to this question?
    If we've never seen something happen, we can't know if its impossible.
    If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
    If someone orders you to disobey all of their orders, do you obey or disobey?

  26. #26
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Not strange. The RTL defines _mainCRTStartup which does all the command-line processing and sets things up (like static constructors ).

    So actually, you have windows.h included anyway
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width