Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? I don't think i use all the 10 MB of Qt library code.

like image 657
pavelkolodin Avatar asked Feb 24 '26 18:02

pavelkolodin


1 Answers

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. You can do this by adding -flto to all your g++ calls. This lets the g++ add so called GIMPLE code to your object files which corresponds to your source (so it is not completly compiled). In the linking step you should add -fwhole-program or -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. However I cannot garantee this works for you.

like image 58
Haatschii Avatar answered Feb 27 '26 06:02

Haatschii