Qt: Static vs Dynamic Linking

Mihail Mihalache
2 min readDec 8, 2020

--

Performance vs Lightweightness

Photo by Hassan Pasha on Unsplash

TL;DR —With Static linking the required libraries are included within the executable. With Dynamic linking the required libraries are expected to be available at a specific location at runtime.

Static Linking

Static linking produces a stand-alone executable, so this means less files to deploy, but a larger executable. Also, the application would take longer to build.

The main advantage of static linking is the speed of the application at runtime.

A downside of static linking is that adding or updating a plugin requires a complete rebuild and redeployment of the application. — Source: Linking to Static Builds of Qt

Dynamic Linking

Dynamic linking results in an executable that depends on the linked libraries being available. So deployments will include more files, but the application itself will be smaller. This is great for applications with frequent deployments.

The main advantage with dynamic linking is that compile takes less time to complete and the executable is smaller. Also, the user is able to independently update the Qt library used by the application.

Conclusion

For development, where you need to do many quick compiles, I would argue dynamic linking is the obvious choice.

For deployment, I would choose:

Static Linking when:

  • the application needs to have a high execution performance
  • a larger application size is not an issue
  • a longer build time is not an issue
  • security is essential (you compile all the libraries from the official source code)

Dynamic Linking when:

  • execution performance is not essential
  • you need to deploy frequently
  • several applications use the same libraries on a machine with limited disk space
  • security is not essential (that’s because the user might already have installed a version of Qt or a specific library, built by a 3rd party, whose legitimacy and integrity you can’t guarantee)

Reference

C++ Development Tutorial 4: Static and Dynamic Libraries

Deploying Qt Applications

Static Libraries vs. Dynamic Libraries

Shared (dynamic) Libraries vs. Static Libraries — Differences in performance.

--

--