4

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?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
abirvalg
  • 128
  • 1
  • 7
  • A related question about eliminating dead code, though not specifically about Qt: [How can I know which parts in the code are never used?](https://stackoverflow.com/q/4813947) – tanius Jun 09 '20 at 15:06

3 Answers3

8

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.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • 1
    Not entirely true. No tool, not even the linker, can be used to 100% detect whether certain plug-ins like the PNG or JPEG loaders are actually used. You'd have to check the filenames that are loaded. A linker doesn't even try. – MSalters Jul 25 '11 at 08:22
1

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

Raiv
  • 5,731
  • 1
  • 33
  • 51
  • Great tip! The effect is much more than I expected: "UPX will typically reduce the file size of programs and DLLs by around 50%-70%" (says the [UPX Github README](https://github.com/upx/upx)) – tanius Jun 09 '20 at 15:22
0

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.

tanius
  • 14,003
  • 3
  • 51
  • 63