This is worse for Windows with gcc:
main.c:
#include <stdio.h> int main( int argc, char* argv[] ) { return 0; }
compilation:
C:\>gcc main.c
The size:
C:\>size a.exe text data bss dec hex filename 6936 1580 1004 9520 2530 a.exe
bss includes the entire associated executable, in which case different libraries are linked that use static c-initialization.
Usage - nostartfiles gives a much better result for windows. You can also try with -nostdlib and -nodefaultlibs
compilation:
C:\>gcc -nostartfiles main.c
The size:
C:\>size a.exe text data bss dec hex filename 488 156 32 676 2a4 a.exe
Remove all the libraries (including the c library) and you will get an “executable” with what you compiled and the size of bss is 0:
main.c:
#include <stdio.h> int _main( int argc, char* argv[] ) { return 0; }
compilation:
C:\>gcc -nostartfiles -nostdlib -nodefaultlibs main.c
The size:
C:\>size a.exe text data bss dec hex filename 28 20 0 48 30 a.exe
The executable will not work.
Brian sidebotham
source share