abirvalg
abirvalg

Reputation: 148

How can I strip down the Qt libraries to remove stuff not used by my application?

I'm shipping a stand-alone Linux application with Qt libraries compiled-in.

Is there a tool which would scan my source code, see which classes/methods my app uses, then it would pluck the unnecessary/unused stuff out of the Qt source code and compile Qt libraries tailor-made for my application without any extra bloat? This is the best case scenario, of course. But what is the closest existing solution that would allow me to make my Linux stand-alone app with compiled-in qt libs as slim as possible?

Upvotes: 4

Views: 2004

Answers (3)

tanius
tanius

Reputation: 16899

what is the closest existing solution […] to make my Linux stand-alone app with compiled-in Qt libs as slim as possible?

Specifically for Qt, since early 2019 there is the build process configuration option -ltcg to enable link-time code generation. According to the Qt company blog, it allows 15% size reduction for statically linked Qt and a smaller but still noticable effect for dynamically linked Qt libraries.

Upvotes: 0

Raiv
Raiv

Reputation: 5781

for additional size reduction of your program try UPX - it will make your application even smaller.

Upvotes: 1

Cody Gray
Cody Gray

Reputation: 245022

Is there a tool which would scan my source code, see which classes/methods my app uses, then it would pluck the unnecessary/unused stuff out of the Qt source code and compile Qt libraries tailor-made for my application without any extra bloat?

The linker already does this for you. If you're statically linking to the Qt libraries, then only the code for the functions that you're calling will be embedded into the executable.

You don't need an external piece of software to do this. It doesn't matter how big the Qt libraries are on your development machine.

Upvotes: 8

Related Questions