Large exe file on mingw

This is a discussion on Large exe file on mingw within the Windows Programming forums, part of the Platform Specific Boards category; I installed mingw on my linux computer to compile executable files for windows. The problem is the generated exe files ...

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    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
    4,165
    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, 09: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, 03: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, 03:06 AM

Tags for this Thread


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