注册 登录
编程论坛 C语言论坛

如何让编译生成的C程序小于1KB

yuma 发布于 2025-12-04 19:59, 552 次点击
程序代码:
#include <windows.h>
void _start() {
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    const char msg[] = "Hello World\n";
    DWORD written;
    WriteFile(hOut, msg, 12, &written, NULL);
    ExitProcess(0);
}


编译:

gcc -Os -ffunction-sections -fdata-sections -nostartfiles -fno-asynchronous-unwind-tables -fno-stack-protector -fomit-frame-pointer -Wl,--gc-sections,--entry=_start,--strip-all,--image-base=0x400000,--file-alignment=256 -lkernel32 main.c -o hello_win.exe


生成的文件还是无法在1KB之内,如何优化,可以让编译生成1KB以内?

只有本站会员才能查看附件,请 登录
2 回复
#2
yiyanxiyin2025-12-04 22:35
不要用windows.h
#3
yuma2025-12-05 11:09
那你写一个看看。编译后看能有多小。
1