Why is my C++ executable so big? [duplicate]

血红的双手。 提交于 2019-11-29 12:07:11

Statically linking the C and/or C++ runtime can greatly increase the size. Also, compiling your program to include debugging information can increase the size.

It probably is with debug information. If you strip that out (by building in release mode in Visual Studio, or using the strip command in Linux) it will be much smaller.

This is almost certainly because you created a static executable, i.e. one which can run standalone and doesn't rely on run-time libraries. See for the documentation of your compiler/linker for how to avoid that.

Edit:

From your code I get 13540 bytes for a dynamically linked executable (gcc 4.3.2 on linux) but 6.7Mb for a statically linked executable.

Do not to link you app static. Try to make it dynamic.

building in Debug mode will compile and link code that is not optimise in any way (speed/size) and you end up with bloated exec that includes debug version of system libs.

if you switch to release mode, the compiler and linker can be optimised to only use the functions they require in the final exec and also use their release versions. that way you will end up with 'hopefully' a smaller exec if you've selected optimise for space.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!