如何减少MinGW g ++编译器生成的可执行文件的大小? [英] How to reduce the size of executable produced by MinGW g++ compiler?
问题描述
我有一个普通的Hello worldC ++程序,编译为500 KB可执行的MinGW g ++编译器在Win XP下。
有人说是由 iostream 库和 libstdc ++。dll 的静态链接引起的。
-s 编译器选项帮助了一点(减少了50%的大小),但我只能满足< 10kB可执行。有什么办法如何使用MinGW编译器实现这一点?可移植性对我来说不是一个大问题。
是否可以使用动态链接复制libstdc ++。dll与可执行文件?
我已经使用MinGW 3.4了。 现在我更新到最新的MinGW 4.6和大小减少了90%到50kB, -s 选项甚至到9kB,这是完全足够的。反正 - 感谢大家的帮助。这里你去我的结果C ++ Hello World 程序使用iostream
MinGW |没有选项| -s选项
------------------------------
3.4 | 500kB | 286 kB
4.6 | 50kB | 9 kB
要使用的标记:
$-
li>
-lstdc ++ _ s
指定动态链接libstdc ++。dll
-
-Os
可优化二进制文件的大小。
mingw静态链接到Windows上的 libstdc ++。a
。
注意 lstdc ++ _s
标志只在MinGW,GCC> 4.4,我相信。
I have a trivial "Hello world" C++ program that is compiled to 500kB executable by MinGW g++ compiler under Win XP. Some say that is caused by iostream library and static link of libstdc++.dll.
Using -s compiler option helped a bit (reducing 50% size), but I would by satisfied only by <10kB executable. Is there any way how to achieve this using MinGW compiler? Portability is not a big concern for me.
Is it possible to copy libstdc++.dll with the executable using dynamic linking? If so, how to achieve this?
Solved: I was using MinGW 3.4. Now I updated to latest MinGW 4.6 and the size was decreased by 90% to 50kB, with -s option even to 9kB, which is fully sufficient. Anyway - thanks everyone for help. Here you go my results
C++ Hello World program using iostream
MinGW | no options | -s option
------------------------------
3.4 | 500kB | 286 kB
4.6 | 50kB | 9 kB
Flags to use:
-s
like you've been doing to strip symbols-lstdc++_s
to specify dynamically linking against thelibstdc++.dll
-Os
to optimize the binary for size.
By default mingw static links to libstdc++.a
on Windows.
Note that the lstdc++_s
flag is only in MinGW with GCC > 4.4, I believe.
这篇关于如何减少MinGW g ++编译器生成的可执行文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!