mingw32-g++ size concerns

This is a discussion on mingw32-g++ size concerns within the C++ Programming forums, part of the General Programming Boards category; I've been rather alarmed at the size of the binaries of simple "Hello world" tests compiled with mingw32-g++. I used ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    67

    mingw32-g++ size concerns

    I've been rather alarmed at the size of the binaries of simple "Hello world" tests compiled with mingw32-g++. I used the minimal console template project in Code::Blocks to do the C version and with the debug info stripped, it's a good 5.5kb which is pretty decent and okay. I then try the C++ version of C::B's console project template (which uses the iostream instead of stdio.h of course) and even with debug symbols stripped it compiles into 269kb (!)

    Is C++'s iostream, compared to C's stdio.h, really that much bigger? If it's possible, does MinGW have a compiling method of compiling only what's actually used in the application, or is it already doing that and C++ just uses that much more in size?

    I mean, small example is of course not that big a deal, but when I go into more complex projects, that will probably make a difference.

    I know stuff made in VC9 is smaller and faster, but I've used GCC a lot more and it's my compiler of preference... Besides, VC9, in some cases, has required C++ language differences that don't apply to cross platform compilers. Like, in some C++ books I've read there was commented code with the note "Uncomment if using VC++"

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,632
    Is C++'s iostream, compared to C's stdio.h, really that much bigger? If it's possible, does MinGW have a compiling method of compiling only what's actually used in the application, or is it already doing that and C++ just uses that much more in size?
    Read the MinGW Wiki on Reasons for 'large' objects, libraries and executables.

    I mean, small example is of course not that big a deal, but when I go into more complex projects, that will probably make a difference.
    As noted on that wiki page, the overhead is usually fixed, so the relative difference in executable size will actually decrease as your project becomes more complex.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    67
    I did use the strip command and I didn't use the -g parameter. It's still large.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,632
    I did use the strip command and I didn't use the -g parameter. It's still large.
    Yes, and that is the overhead and I was talking about, which is also mentioned in that wiki page:
    When you use template classes such as the Standard Template Library, the compiler generates code separately for each instantiation (e.g. vector<int> and vector<string>) so the total code size can increase significantly. Other elements of the standard library such as iostreams, exception handling and std::string can seem large compared to small "Hello World" type programs but this overhead is generally constant so it will not be significant in more realistic applications.
    In other words, you usually can ignore this in a real project, though it may seem disturbing for "Hello world".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    67
    Ah, that's good. If it's a fixed overhead I'm fine with it.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    Quote Originally Posted by Chris87 View Post
    Besides, VC9, in some cases, has required C++ language differences that don't apply to cross platform compilers. Like, in some C++ books I've read there was commented code with the note "Uncomment if using VC++"
    That should not be true.
    At least not anymore. It's true that VC9 has language extensions, but it should compile standards compliant code fine.
    Do you have an example of somewhere you've heard/seen that?
    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
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    By default, MinGW dynamically links to the C runtime that is available on most versions of Windows.

    For the longest time however, it statically linked to libstdc++, and it is very likely that this is why you are seeing such an executable size difference.

    Here is a snippet from the latest release notes however:

    NEW FEATURES SINCE MINGW GCC 3.4

    Windows-specific:

    ....

    -Shared libstdc++: Add -lstdc++_s to your link flags to link against a DLL
    version of libstdc++.

    ....
    So make sure you have one of their V4 releases and try that. It should significantly decrease your executable size, at least for a simple hello world app. For example, here's a little test I did with a simple hello world app (my source code was in test.cpp):

    Code:
    CommandLine                          Executable Size
    
    g++ test.cpp                         844kb
    g++ -Os -s test.cpp                  437kb
    g++ test.cpp -lstdc++_s              16kb
    g++ -Os -s test.cpp -lstdc++_s       5kb
    That look about right to you?
    (Keep in mind the runtime dependency this creates though)
    Last edited by arpsmack; 07-30-2008 at 07:49 AM.

  8. #8
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    Latest release notes?! g++ 3.4 is over two years old or something? You should get a 4.3 or something. Be careful when recompiling your kernel, though...

  9. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    Maybe you aren't understanding the meaning of "New Features Since MinGW 3.4". It's a list of features they've added since version 3.4. I honestly can't think of another way to express that -- oh wait... how bout:

    Code:
    SELECT *
    FROM   dbo.Features
    WHERE  VersionAdded > 3.4
    [edit]
    By the way, I feel sad to report that even though MinGW allows you to use a dynamically linked version of the standard C++ library, it is in fact broken. Despite the fact that my examples compiled, the dynamically linked ones crashed immediately upon running them. This is to be expected though, the current MinGW release is an alpha build. Also, a bug has been filed on their SourceForge tracker.
    [/edit]
    Last edited by arpsmack; 07-30-2008 at 03:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Pointer Size Relative To Integers?
    By SMurf in forum C Programming
    Replies: 1
    Last Post: 04-18-2006, 06:58 AM
  3. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 10:27 AM
  4. An exercise in optimization
    By Prelude in forum Contests Board
    Replies: 10
    Last Post: 04-29-2005, 03:06 PM

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