MinGW(GCC) generates gigantic binaries on Windows

closed account (2EwbqMoL)
I'm getting back into my old hobby of programming (I quit for over a year after frustration)... and I downloaded and installed 2 C++ compilers (as well as a pascal compiler and some others but thats besides the point...)

anyway onto the topic, I compiled one small page of C++ code that calculates state income tax, and Microsoft Visual C++ express compiled it all faster than Dev-C++ w/ mingw by a small margin. Also, more majorly, the compiled executable was about 22Kb from VC++...

the one compiled with MinGW was almost 500kb!!! both IDEs/Compilers were using default settings, and both compiled the exact same code -- only the standard C++ library was used <iostream>, and it was relatively straightforward simple, clean code.

I'm probably going to continue to use Visual C++ anyway (I'm sick of GCC tools -- they're amazing but no longer new and exciting to me lol), but is there any way to knock down those file sizes, or is it some problem stemming from the windows ports of GCC?

I know binaries arent that big on any of the linux boxes I use GCC on.
Last edited on
closed account (z05DSL3A)
Does this help?
http://www.mingw.org/MinGWiki/index.php/executables%20large
Last edited on
Another thing not mentioned by that link is that Linux installations typically compile executables with dynamically linked libraries. This is easy to do because Linux typically keeps libraries in relatively standard places.

On windows, however, you cannot make any assumptions about what libraries the user has, and so a lot of stuff that is dynamically linked to the executable on linux must be statically bound to the windows executable.

You can change these default behaviors if you want, but you must also be aware of the consequences. On Linux, that would mean larger executables, but the resulting ELF could be used on any uber-stripped down version of Linux you want without any grief. On Windows, that would mean that your installer must come with the proper libraries (DLLs) anyway and make sure they are on the target system before the program can be used. You'd sure get a nice, small EXE file though.

VC++ can "cheat" because all the libraries that VC++ uses are already installed on Windows computers. Moreover, VC++ can optimize specifically for Win32/x86 architectures, where GCC must be able to work on the vast majority of systems out there. There is only so much optimization that an assembler can do given a limited instruction set.

(I have found that my old Delphi 5 produces the smallest executables though.)

Hope this helps.
Last edited on
closed account (2EwbqMoL)
I might just stick with VC++ on windows until I come across major problems then...

I mean, I'd like to have as small executables as possible -- I do use other compilers on other systems, and its not a political choice (choosing MS) but rather a choice of which seems to be better suited to windows development...

perhaps the intel compiler would be even better but I cant warrant spending money on it...
I read the Intel compiler optimizes very well.
Yes, the Intel compiler is amazing.

Mike Pan (mpan3) over at www.BlenderArtists.org always compiles an Intel-optimized version of Blender on every new release and the difference in performance is quite noticeable.

spiroth10
That sounds fine. There's no real stigma to using MS tools (he says...). But seriously, in the real world the toolset is dictated by business concerns and nothing else. Compiler/Language zealots hate that.

The only real "problem", if you will, will be keeping the code standard C++ where that is important. You can make VC++ compile very strictly if you like, but the defaults are much friendlier for windows development with MS extensions (for example, merging SEH with C++ exception handling).
Last edited on
closed account (2EwbqMoL)
I'll admit that to me, standards compliance doesnt seem as important as it should... as a matter of fact, I cant even really see how that would effect me...

I could go with another compiler (and by all other means I might screw with some). I've tried most of the free ones, and if I try a paid one, I *might* just go use a certain torrent search engine...

I may look into different compilers simply because the IDE on VC++ is a bit clunky... I might look into borland and intel (< the latter if I can find an IDE for it).

but then again I might stick to VC++ too... the main thing I didnt like about MinGW and other GCC variants was the compiled size...

all though I will say there is a kickass IDE for mingw called MinGW Studio and I used to use that a lot.
Last edited on
Eclipse + CDT should work happily with Intel compiler.
However, if you use "strip" on Mingw you can reduce the size of EXE binary, removing some "simbols" from EXE.

A program of 500k will became a program of 300k (it depends).

1
2
3
4
5
6
7
8
9
10
# MakeFile for MinGw
CC = 
EXE = application.exe
OBJS = application.o module.o

$(EXE): $(OBJS)
     gcc -o $(EXE) $(OBJS)
     strip $(EXE)

application.o: ... etc
Well when linking little programs i get low size executables, even less with stripping(compile optimizing with -s option, like gcc -O3 -s)(i.e. 7,50Kb). When your program grows in size and you start linking libraries, specially static ones, binaries can be pretty big, even with stripping. The size can be high even when compilling everything dinamically, compared to VC. Here VC seems to do a better work removing not reachable code from binary.

I dunno what gcc version you using, latest version is gcc 4.3.2, you can get experimental windows builds from TDM (very stable i would say) from here:

http://www.tdragon.net/recentgcc/

You can find instructions in TDM page. Usually all you have to do is have mingw installed then decompress the files inside mingw directory directly, very easy.
(i think tdm now provides an internet installer that will install you everything, mingw plus latest gcc build and other tools)

Another issue with gcc is that it has loads of options and you really need to study them, you can get gcc 4.3.2 manual(pdf) here:

http://gcc.gnu.org/onlinedocs
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc.pdf


As a side note, devcpp havent updated in a while. I would use (actually i do) codeblocks:

http://www.codeblocks.org/

This is a pretty good cross platform IDE, the only thing that i miss compared to VC is a better integrated help system, something very useful.
You can use this IDE not only with GCC but with VC compiler, Intel compiler and some others.
You have a codeblocks+mingw bundle fo download, but i actually prefer to have separate installations for mingw and codeblocks.
Current codeblocks version is 8.02 but you can get aswell latest codeblocks nighty build(with some bugfixs but experimental build of course).
By the way, codeblocks comes with wxSmith plugin that will allow you to do visual programming, you have to check it, it is not crappy visual develoment but a real good one, you will need wxWidgets SDK for your platform:

http://www.wxwidgets.org

wxWidgets is a crossplatform windowing framework similar to mfc from microsoft. Actually codeblocks has been developed using wxWidgets.

You will need to download wxMSW 2.8.x from www.wxwigets.org if youre using windows,

decompress (i.e. C:\wxSDK) and in (C:\wxSDK\build\msw) directory do(supossing you have mingw already installed):

mingw32-make -f makefile.gcc MONOLITHIC=1 SHARED=1 UNICODE=1 BUILD=release clean

wait.... and youre ready to do visual editing with codeblocks with the wxsmith plugin

(and you could rebuild youre app in other platform that supports wxwidgets, like linux, mac, ...)
Last edited on
The 500 KByte executables are generated by using "iostream".
Simply circumvent this and you will get 100 KByte executables without any optimization and stripping, smaller ones with optimizations and stripping, of course.

The few necessary code lines for a convenient cout/cin-replacement are a matter of some minutes.
Make sure not to compile with the -g option (produce debugging symbols)
this options is used only in debug versions and makes large executables.
OK, but why should you have to do any work-around at all?

e.g. a Borland-compiled "Hello World" gives a .exe a fifth the size of MinGW's compiler with no options. Microsoft gives even smaller executables.

http://www.mingw.org/MinGWiki/index.php/executables%20large

The above link does not work. Can anyone point me to any info on this?
Last edited on
The reason is because Borland/Microsoft can assume the locations of many of the includes, since you are running on a windows computer, meaning they do not have the statically include them into the .exe, instead they can just dynamically link them.
Topic archived. No new replies allowed.