用于最小可执行文件的 C++ Windows 编译器 [英] C++ Windows Compiler for smallest executables

查看:52
本文介绍了用于最小可执行文件的 C++ Windows 编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我想开始用 C++ 编程.我已经用 vb6、vb.net 编写了一些程序,现在我想获得 C++ 的知识,我想要的是一个可以将我的代码编译为最小的 Windows 应用程序的编译器.例如,有一个名为 PureBasic 的基本语言编译器,它可以使 Hello world 独立应用程序的大小为 5 kb,而我编译的简单套接字程序只有 12 kb(没有任何 DLL-s 和运行时文件).我知道这很棒,所以我想要这样的 C++.

guys I want to start programing with C++. I have written some programs in vb6, vb.net and now I want to gain knowledge in C++, what I want is a compiler that can compile my code to the smallest windows application. For example there is a Basic language compiler called PureBasic that can make Hello world standalone app's size 5 kb, and simple socket program which i compiled was only 12kb (without any DLL-s and Runtime files). I know it is amazing, so I want something like this for C++.

如果我错了,而且没有这种 Windows 编译器,谁能给我一个网站或书籍,教我如何减少 C++ 可执行文件的大小,或者如何使用 Windows API 调用?

If I am wrong and there is not such kind of windows compiler can someone give me a website or book that can teach me how to reduce C++ executable size, or how to use Windows API calls?

推荐答案

多年前我不得不用 VC6 来做这件事.这是必要的,因为可执行文件将通过网络传输到目标计算机,并在那里运行.由于它可能通过调制解调器连接发送,因此需要尽可能小.为了缩小可执行文件,我依赖于两种技术:

I had to do this many years ago with VC6. It was necessary because the executable was going to be transmitted over the wire to a target computer, where it would run. Since it was likely to be sent over a modem connection, it needed to be as small as possible. To shrink the executable, I relied on two techniques:

  1. 不要使用 C 或 C++ 运行时.告诉编译器不要链接它们.使用当时所有版本的 Windows(98、Me、NT、2000)都保证可用的 Windows API 子集实现所有必要的功能.
  2. 告诉链接器将所有代码和数据段合并为一个.我不记得这个开关,我不知道它是否仍然可能,尤其是对于 64 位可执行文件.

最终的可执行文件大小:~2K

The final executable size: ~2K

这篇关于用于最小可执行文件的 C++ Windows 编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆