Why is the smallest compiled exe I can do with GCC is 67KB?

I would like to make a very small compiled exe that was written in C. But the smallest I could get is 67KB. I am using MinGW. I tried not to use any header file, and this compiles without errors:

//no header
void main() {
 write(1, "Hello world!", 12);
}

GCC does not show errors if I create and run this, but also 67KB.

+4
source share
1 answer

I just tried this on x86_64 Linux, which is probably not much different from MinGW at this level, although you never know.

, , C, , CRT "startfiles" , , , "Hello world", . , , .

, , , . , , .

:

#include <unistd.h>

void _start (void) {
  write(1,"Hello world!", 12);
  _exit(0);
}

: gcc -nostartfiles t.c -s -static

(, . ) 1792 .

, 738624 , , 4400 , -static, ! ( -static, write _exit).

, . , . , x86_64 Linux ( , ?) , -m32, write.

, ( ). , .

+2

Source: https://habr.com/ru/post/1614959/


All Articles