Thread: Large exe file on mingw

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    5

    Large exe file on mingw

    I installed mingw on my linux computer to compile executable files for windows. The problem is the generated exe files are so large around 5-8mb. Is that normal for mingw compiler? How can I make my compiled code smaller?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You're probably using static linking. If you could use dynamic linking, you would probably end up with a smaller exe, although it will require the appropriate runtime to be installed on the target machine.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by kuchiku View Post
    I installed mingw on my linux computer to compile executable files for windows. The problem is the generated exe files are so large around 5-8mb. Is that normal for mingw compiler? How can I make my compiled code smaller?
    Turn off debugging symbols... they bloat the he.. out of software.

    The smalest MinGw program ("Hello World") comes in at a rather surprising 200k with no debugging stuff in it.

    If executable size is an issue you might try Pelles C ... starting about 20k, 8k for windows... or Tiny C which starts at about 8k.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    FALSE. Experiments show that debug info adds another ½ KB for a Hello World program.
    What bloats the executable is static linking and debug builds (32 KB vs 8 KB).
    (Tested using Visual C++ 2010. Your results on mingw may vary.)
    Last edited by Elysia; 05-23-2011 at 09:28 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Elysia View Post
    FALSE. Experiments show that debug info adds another ½ KB for a Hello World program.
    What bloats the executable is static linking and debug builds (32 KB vs 8 KB).
    Did you do your experiments with MinGW? Sometimes I think you jump to conclusions a bit too quick.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Admittedly, I didn't. My bad.
    I don't know how to compile debug vs release builds on mingw, though.
    If anyone can prove me wrong, I shall eat those words.
    I can vouch that debug info does not bloat executable using Visual C++, though.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Elysia View Post
    Admittedly, I didn't. My bad.
    I don't know how to compile debug vs release builds on mingw, though.
    If anyone can prove me wrong, I shall eat those words.
    I can vouch that debug info does not bloat executable using Visual C++, though.
    Visual C++ produces a big wad of stuff when you compile for debug, it's just that it puts it in a separate file (.pdb). Check out the size of that sucker sometime.

    As far as the OP's question, the size is probably due to the massive bloat of whatever C runtime is being used by MinGW (probably GNU).
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Are we discussing debug info (ie debug symbols) in the EXE or debug builds (that is, executables built for debugging)?
    Debug info tends to be embedded into the exe in both release and debug, and to my knowledge does not bloat the size significantly.
    Debug executables on the other hand bloats the size enormously. But they wouldn't run on another machine without Visual Studio installed.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    The problem is the generated exe files are so large around 5-8mb.
    You've either statically linked a huge chunk of code or are grossly exaggerating the size. In the first case, nothing can be done if you need to statically link that much code. (If you don't need to statically link but do need that much code, why aren't you using a dynamically linked library?) In the second case, don't exaggerate about how large the files are.

    The smalest MinGw program ("Hello World") comes in at a rather surprising 200k with no debugging stuff in it.
    That would be false.

    The smallest C program is 8KB with or without the minimum necessary statically linked "libgcc" and no compiler fluff.

    The smallest C++ program is approximately 200K or 400K (it depends on the version of "libstdc") with a statically linked "libgcc" and "libstdc++" and no compiler fluff.

    The smallest C++ program is approximately 8K with a dynamically linked "libgcc" and "libstdc++".

    As far as the OP's question, the size is probably due to the massive bloat of whatever C runtime is being used by MinGW (probably GNU).
    The MinGW port of "GCC" uses the same "MSVCRT.DLL" runtime as older versions of "MSVC". The only increase in size from this would be tiny because the developers have included a wrapper for some routines to fix some bugs in the DLL. (Obviously, they can't just fix the DLL since it isn't their's.)

    It does however use "libstdc++", but that weighs in at less than a MB and can be linked dynamically.

    Soma
    Last edited by phantomotap; 05-23-2011 at 10:43 AM. Reason: none of your business

  10. #10
    Registered User
    Join Date
    May 2011
    Posts
    5
    It is actually the debug stuffs that made the size larger.

    I just check the makefile of the program that I am compiling and found out that the argument "-g" is included in the parameters that is passed to mingw. I just remove that and the size decreased to 800kb. I believe that enabled the compilation of debug symbols.
    Last edited by kuchiku; 05-30-2011 at 12:40 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random file IO problems in MinGW GCC
    By JungleJesus in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2010, 10:53 AM
  2. [Large file][Value too large for defined data type]
    By salsan in forum Linux Programming
    Replies: 11
    Last Post: 02-05-2008, 04:18 AM
  3. Large file i/o
    By Mostly Harmless in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2007, 01:48 PM
  4. File I/O in MingW?
    By Nebbuchadnezzar in forum C++ Programming
    Replies: 15
    Last Post: 07-20-2005, 11:54 PM
  5. large bitmap file
    By sunis in forum Windows Programming
    Replies: 3
    Last Post: 01-16-2003, 04:06 AM

Tags for this Thread