Possible Duplicate:
Why is a C/C++ “Hello World” in the kilobytes?
Consider the following program written in ANSI C.
file: test.c
main() {}
I’m on Windows 7. I use MinGW to compile this file.
$ gcc test.c
Then, I want to see the size of this file.
$ ls -la a.exe
-rwxr-xr-x 1 Username Administrators 47902 Nov 21 15:57 a.exe
It appears that this completely empty, worthless C program compiles to a binary that is almost fifty kilobytes in size. Why in the world is this happening?
Run GCC like
gcc -v test.c. The GCC (the compiler driver) spawnscc1(the compiler),as(the assembler) andld(the linker). Look at the linker command line and you’ll see several files (something likecrti.o,crt0.o,crtbegin.o,crtend.o, etc.) linked in the final executable. ANd some of them may fetch symbols fromlibgcc.aorlibc.a. That explains why the size is not just a few bytes.You could also run it with
-Wl,-Map=map.txtto generate a map file, which will reveal every function or variable from every object and library, which is included in the final executable.