c - MinGW - 为什么 C 'hello world' 可执行文件有 42kb?

标签 c windows gcc tcc

如果我用 MinGW 编译 C hello world,生成的 exe 大小为 42Kb。如果我使用 Tiny C 编译器,我会得到 2Kb 的东西。 (在这两种情况下,无需指定任何选项或执行任何有趣的操作,只需 gcc hello.c -o hello.exe)

现在我知道需要最少的启动代码;但是 mingw 放在那里的额外 40kb 的东西是什么,它有什么作用,为什么需要它?

最佳答案

来自the FAQ :

Debugging Information

The most common reason why executables are larger than expected is that they include debugging information, which is generated when source files are compiled with the "-g" option to GCC. Even when your own source files are compiled without debugging information, libraries linked with your executable may have been compiled with "-g" (possibly including system libraries that are distributed with MinGW).

To exclude debugging information from your executable, simply use the "strip" command to remove it, or alternatively use the "-s" option when linking.

UPX (Ultimate Packer for eXecutables)

UPX is a tool that can decrease the size of executables, using very fast and very efficient in-place compression/decompression. It works for Windows and Linux executables and is free for use with all applications (including commercial apps).

关于c - MinGW - 为什么 C 'hello world' 可执行文件有 42kb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40693482/

相关文章:

C - 矩阵 > 仅正元素

c++ - gcc 链接错误 : undefined reference to symbol '_ZN2cv5flann12SearchParamsC1Eifb' ,

c - 从 main.c 中进行单个定义,以便在编译时可用于库

Python ConfigParser 到 C++

c - sizeof(size_t) < sizeof(unsigned int) 的实际实现

windows - 如何让 Windows 8.1 知道我的 Delphi 应用程序想要支持 Per Monitor DPI?

windows - 在 Windows 上运行 Syntaxnet

windows - C++ try-catch block 无法捕获硬件异常

c - 使用 scanf 处理多种数据类型

c - 如何在 C 中的结构中存储可变长度数组