简体   繁体   English

链接后最小的可执行文件大小

[英]Minimal executable size after linkage

I link with Qt statically, so can linker or some other tool avoid adding unused binary code (from Qt libraries) to the final executable? 我静态地链接Qt,链接器或其他工具可以避免将未使用的二进制代码(从Qt库)添加到最终的可执行文件中吗? I don't think i use all the 10 MB of Qt library code. 我不认为我使用所有10 MB的Qt库代码。

If you compile the Qt library yourself at some point and you are using the g++ you should try to use the Link Time Optimisation (LTO) options. 如果您在某个时刻自己编译Qt库并且使用的是g ++,则应尝试使用链接时优化(LTO)选项。 You can do this by adding -flto to all your g++ calls. 您可以通过在所有g ++调用中添加-flto来完成此操作。 This lets the g++ add so called GIMPLE code to your object files which corresponds to your source (so it is not completly compiled). 这让g ++将所谓的GIMPLE代码添加到与源相对应的目标文件中(因此它不是完全编译的)。 In the linking step you should add -fwhole-program or -fuse-linker-plugin. 在链接步骤中,您应该添加-fwhole-program或-fuse-linker-plugin。 The gcc then reads the Gimple code, and optimises your program as a whole, therby it should be able to get rid of any unused code. 然后gcc读取Gimple代码,并优化整个程序,因此它应该能够摆脱任何未使用的代码。 However I cannot garantee this works for you. 但是我不能保证这件作品适合你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM